Monkuar Posted January 25, 2012 Share Posted January 25, 2012 Ok Let's say I have a timestamp: 1327482941 I want to convert this to output only "60" im not looking for a whole time_ago function, simply just need to convert a timestamp down to seconds ONLY not having minutes/years/etc no need none of that just purely seconds starting from 1-60 if so how is it possible? I tried to just $seconds = substr($e,1,4) . ""; $e is my timestamp, I did this because I could just grab the last 2 digits in the timestamp that would be what I want, but that's not possible because it goes 1-90 not 1-60 help Here is a code I am trying to make it only spit out 1-60 in seconds function timeAgo4($timestamp, $granularity=1){ $difference = $timestamp; if($difference < 0) return '0'; elseif($difference < 86400){ $periods = array(60,'' => 1); $output = ''; foreach($periods as $key => $value){ if($difference >= $value){ $time = round($difference / $value); $difference %= $value; $output .= ($output ? ' ' : '').$time.' '; $granularity--; } if($granularity == 0) break; } return ($output ? $output : '0').''; } else return date($format, $timestamp); } Link to comment https://forums.phpfreaks.com/topic/255743-need-to-convert-a-timestamp-into-seconds-only/ Share on other sites More sharing options...
Monkuar Posted January 25, 2012 Author Share Posted January 25, 2012 WOW IM SO RETARDED $seconds = date("s", $e); LOL!!!! OMG... Link to comment https://forums.phpfreaks.com/topic/255743-need-to-convert-a-timestamp-into-seconds-only/#findComment-1310990 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.