-
Fetching datetime...
Hi....
I was fetching datetime.. but I'm trying to add 3 hours to the HOUR and I used mktime() function but it didn't work..
Also I have a question with this.. if I add 24 hours to the HOUR will it update the date automatically?
This is the dateformat I'm trying to fetch and replace from the database
date("Y-m-d H:i:s");
Someone help me please~
-
Re: Fetching datetime...
I've always hated working with time. :)
It, mathematically, should add the date after 24 hours, test it and see.
PHP Code:
$time = strtotime('+24 hours');
echo date("Y-m-d H:i:s",$time);
Googling around I eventually came across this,
[ame="http://www.webdeveloper.com/forum/showthread.php?t=62042"]convert mysql DATETIME to timestamp ?? - WebDeveloper.com[/ame]
PHP Code:
/*
* Function to turn a mysql datetime (YYYY-MM-DD HH:MM:SS) into a unix timestamp
* @param str
* The string to be formatted
*/
function convert_datetime($str) {
list($date, $time) = explode(' ', $str);
list($year, $month, $day) = explode('-', $date);
list($hour, $minute, $second) = explode(':', $time);
$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
return $timestamp;
}
So that makes your DATETIME result a UNIX Timestamp (the long unreadable number) instead.
With that, see if you can do this:
PHP Code:
//Convert to UNIX Timestamp
$time = convert_datetime( $row['Your_Datetime_Variable'] );
//Add 3 Hours
$time = strtotime('+3 hours',$time);
//Test Result
echo date("Y-m-d H:i:s",$time);
-
Re: Fetching datetime...
Thanks SPN.
I was mainly on PHP.net looking I tired google once but I hate google.
Aaron