matt0268 Posted October 6, 2012 Share Posted October 6, 2012 <?php $channel = "mattbenson"; $json_file = @file_get_contents("http://api.justin.tv/api/stream/list.json?channel={$channel}", 0, null, null); $json_array = json_decode($json_file, true); if( array_key_exists( '0', $json_array ) && array_key_exists( 'channel', $json_array[0] ) && $json_array[0]['name'] == "live_user_{$channel}" ) { $channelTitle = $json_array[0]['channel']['title']; $title = $json_array[0]['channel']['status']; $viewers = $json_array[0]['channel_count']; $uptime = $json_array[0]['up_time']; $today = date("D M j d:i:s Y"); $uptime1 = ($today - $uptime); printf('Online'); printf ($uptime1); print "<br>"; print "date <--- "; printf ($today); print "<br>"; print "uptime <--- "; printf ($uptime); } else { printf('Offline'); } ?> It displays like this Online0 date <--- Sat Oct 6 06:34:51 2012 uptime <--- Sat Oct 6 06:15:44 2012 Problem is it doesn't subtract is just displays 0 Anyhelp? Link to comment https://forums.phpfreaks.com/topic/269161-subtracting-time-from-time-help/ Share on other sites More sharing options...
scootstah Posted October 6, 2012 Share Posted October 6, 2012 Use strtotime to get the UNIX timestamp of both dates, and then do the subtraction, and then use date again. Link to comment https://forums.phpfreaks.com/topic/269161-subtracting-time-from-time-help/#findComment-1383224 Share on other sites More sharing options...
matt0268 Posted October 6, 2012 Author Share Posted October 6, 2012 Use strftime to get the UNIX timestamp of both dates, and then do the subtraction, and then use date again. Thanks for the response, i'm confused on how i can get the strftime from both dates? I'm using an API to get the date from one. If you could help me out i would appreciate it! Link to comment https://forums.phpfreaks.com/topic/269161-subtracting-time-from-time-help/#findComment-1383227 Share on other sites More sharing options...
scootstah Posted October 6, 2012 Share Posted October 6, 2012 Oops, I meant to say strtotime. Sorry about that. Link to comment https://forums.phpfreaks.com/topic/269161-subtracting-time-from-time-help/#findComment-1383228 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.