Page 1 of 1
php date
Posted: Sat May 09, 2009 11:30 pm
by VarwigDude
I can't seem to get this. I want to get a date from a mysql row. But i want to add 10 hours to it when I want to display the time.
example
$end_time_and_date = $row['end_time_and_date'] + 10h;
Re: php date
Posted: Sat May 09, 2009 11:42 pm
by mickd
Is it just a mySQL date field? Or datetime field?
If its a date field, it just has YYYY-MM-DD, which could you give an example to what it means to add 10hours to it?
If its a datetime field, YYYY-MM-DD HH:MM:SS, do you want to add 10hours using PHP or during the mySQL query? For PHP,
strtotime can convert your mysql time into a PHP timestamp, and then add 36000 (10*60*60) seconds to it.
Code: Select all
//$mysqlDate from the mysql database datetime field.
$phpDate = strtotime($mysqlDate);
$addTenHours = $phpDate + 36000;
Re: php date
Posted: Mon May 11, 2009 10:59 am
by pickle
mickd wrote:strtotime can convert your mysql time into a PHP timestamp, and then add 36000 (10*60*60) seconds to it.
It's better to just use strtotime() period - as it takes into account any DST time changes. You can also use the MySQL function UNIXTIMESTAMP() to convert from a MySQL timestamp to a UNIX timestamp right in the query
Code: Select all
$final_stamp = strtotime('+10 hours',$row['unix_timestamp']);