Jump to content

PHP derived time data


PJHOPE

Recommended Posts

I have a fairly simple question. I was working on a PHP script which pulled a time stamp from a database. My problem was in getting the time stamp from MySQL in the format 2007-01-29 12:12:12 to be subtracted from the current time and converted into a decimal representing hours (12.88 hrs). Then the current time is inserted back into the DB as the time stamp.

 

Honestly it is just conversion between MySQL standard and the PHP but I cannot find any solutions in any of the books or online guides I have. Any help would be appreciated particularly some code.

 

Thanks all,

 

Joe

Link to comment
https://forums.phpfreaks.com/topic/37370-php-derived-time-data/
Share on other sites

$mysqlTS = "2005-12-01 12:12:12"; // given a mysql timestamp

$numOfSeconds = strtotime($mysqlTS) - time(); // number of seconds from that date to now
$numOfHours = $numOfSeconds/(3600);

echo  "$numOfHours hrs";

 

If $mysqlTS is in the past, you will get negative number of hours.

 

Link to comment
https://forums.phpfreaks.com/topic/37370-php-derived-time-data/#findComment-178736
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.