# IRC bot help - uptime

**URL:** <https://discuss.dev.twitch.com/t/irc-bot-help-uptime/913>\
**Category:** Uncategorized\
**Created:** [June 15, 2014, 10:46am UTC](https://discuss.dev.twitch.com/t/irc-bot-help-uptime/913 "2014-06-15T10:46:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Westpanda](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@Westpanda](https://discuss.dev.twitch.com/u/Westpanda)\
**Post date:** [June 15, 2014, 10:46am UTC](https://discuss.dev.twitch.com/t/irc-bot-help-uptime/913/1 "2014-06-15T10:46:38Z")

</div>

Helping a friend with a custom bot and we can’t find a way to code uptime into the customer bot outside a timer and we rather not use timer commands because someone has to start it. Looking for maybe like what nightbot and other bots have for coding to show the uptime :)!

Thanks for help in advance ! Stay awesome!

---

<div class="post-metadata">

**Author:** ![Schmoopiie](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/schmoopiie/32/121_2.png) [@Schmoopiie](https://discuss.dev.twitch.com/u/Schmoopiie)\
**Post date:** [June 15, 2014, 11:13am UTC](https://discuss.dev.twitch.com/t/irc-bot-help-uptime/913/2 "2014-06-15T11:13:35Z")

</div>

This is the way I get the uptime of a stream:

[http://api.justin.tv/api/stream/list.json?channel=CHANNEL\_NAME](http://api.justin.tv/api/stream/list.json?channel=CHANNEL_NAME) or [http://api.justin.tv/api/stream/list.xml?channel=CHANNEL\_NAME](http://api.justin.tv/api/stream/list.xml?channel=CHANNEL_NAME)

Search for **up\_time**. You will get the date and time when the stream started.

Thanks,  
Schmoopiie!

---

<div class="post-metadata">

**Author:** ![Persil](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@Persil](https://discuss.dev.twitch.com/u/Persil)\
**Post date:** [June 17, 2014, 6:38am UTC](https://discuss.dev.twitch.com/t/irc-bot-help-uptime/913/3 "2014-06-17T06:38:19Z")

</div>

If you’re looking for a mIRC bot based here it is:

```
on *:text:!uptime:#channel_here:{
  uptime
}

alias uptime {
  sockopen tuptime api.justin.tv 80
}

on *:sockopen:tuptime:{
  if ($sockerr) { sockclose $sockname | halt }
  sockwrite -n $sockname GET /api/stream/list.xml?channel=channel_name HTTP/1.1
  sockwrite -n $sockname Host: api.justin.tv $crlf $+ $crlf
}

on *:sockread:tuptime:{
  if ($sockerr) { sockclose $sockname }
  var %streamodata
  sockread %streamodata

  if ($regex(%streamodata,/<up_time>(.*)</up_time>/)) {
    msg #channel_here [Uptime] Streamname_here is online for $duration($calc($ctime - $ctime($regml(1)))) $+ .
  }
}

```

---

<div class="post-metadata">

**Author:** ![darkestdread](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@darkestdread](https://discuss.dev.twitch.com/u/darkestdread)\
**Post date:** [August 12, 2014, 7:35pm UTC](https://discuss.dev.twitch.com/t/irc-bot-help-uptime/913/4 "2014-08-12T19:35:35Z")

</div>

Does anyone have an updated version that works now that [api.justin.tv](http://api.justin.tv) doesn’t exist anymore? I tried to use [api.twitch.tv](http://api.twitch.tv). Though I was not able to get it to work. Would greatly appreciate this.

---

<div class="post-metadata">

**Author:** ![psychedk](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/psychedk/32/133_2.png) [@psychedk](https://discuss.dev.twitch.com/u/psychedk)\
**Post date:** [September 12, 2014, 2:08pm UTC](https://discuss.dev.twitch.com/t/irc-bot-help-uptime/913/5 "2014-09-12T14:08:12Z")

</div>

Which programming language are you writing the bot in?  
No one can help before they know that since there are so many to choose from.

The API URL has been updated.  
[Here you can find all you need to know about the API](https://github.com/justintv/twitch-api)

---

<div class="post-metadata">

**Author:** ![NullBy7e1](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@NullBy7e1](https://discuss.dev.twitch.com/u/NullBy7e1)\
**Post date:** [September 18, 2014, 3:00pm UTC](https://discuss.dev.twitch.com/t/irc-bot-help-uptime/913/6 "2014-09-18T15:00:35Z")

</div>

I am trying to get uptime to work in C#, but whenever I substract created\_at from DateTime.Now the uptime is off by a few hours.  
Probably due to the timezone difference between created\_at and the server.

How can I get around this?

```
string created_at = (string)((JObject)value)["created_at"];
return DateTime.Now - DateTime.Parse(created_at);
```

---

<div class="post-metadata">

**Author:** ![Fugiman](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/fugiman/32/108_2.png) [@Fugiman](https://discuss.dev.twitch.com/u/Fugiman)\
**Post date:** [September 18, 2014, 10:07pm UTC](https://discuss.dev.twitch.com/t/irc-bot-help-uptime/913/7 "2014-09-18T22:07:23Z")

</div>

created\_at is UTC, so ensure it is parsed as UTC and your DateTime.Now is in UTC.

---

<div class="post-metadata">

**Author:** ![darkestdread](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@darkestdread](https://discuss.dev.twitch.com/u/darkestdread)\
**Post date:** [July 28, 2015, 10:30pm UTC](https://discuss.dev.twitch.com/t/irc-bot-help-uptime/913/8 "2015-07-28T22:30:18Z")

</div>

Sorry about the delay. I am scripting with IRC right now. Trying to impliment uptime so that I can use it to use the time to create a highlight time stamp/marker.
