Convert Unix timestamp to hours

Everything,

I have a database field that actually calculates the time spent from the start of the quiz to the current time. This was done at some point in time (recorded as the current time), and now I have a Unixtimestamp value for it

i.e. Suppose the start time was 5/5/2011 1pm and the current time was 5/5/2011 2pm. In this way, the difference is computed and stored as a Unix timestamp.

Now I do not know when this was done, and now I need to return to the hours spent with the quiz. Thus, the Unix timestamp must be converted back to hours, in which case a 1 hour return. Can someone please help me figure out how to do this?

+4
source share
2 answers

You have seconds, so just do something like

SELECT secondsField / 3600 as 'hours' FROM tableName 
+8
source

Here is an example of finding the difference between two timestamps in days.

 //Get current timestamp. $current_time = time(); //Convert user create time to timestamp. $create_time = strtotime('2011-09-01 22:12:55'); echo "Current Date \t".date('Ymd H:i:s', $current_time)."\n"; echo "Create Date \t".date('Ymd H:i:s', $create_time)."\n"; echo "Current Time \t ".$current_time." \n"; echo "Create Time \t ".$create_time." \n"; $time_diff = $current_time - $create_time; $day_diff = $time_diff / (3600 * 24); echo "Difference \t ".($day_diff)."\n"; echo "Quote Index \t ".intval(floor($day_diff))."\n"; echo "Func Calc \t ".get_passed_days($create_time)."\n"; function get_passed_days($create_time) { return intval(floor((time() - $create_time) / 86400)); } 

To convert to hours, instead of 86400, enter 3600 instead.

Hope this helps.

+1
source

All Articles