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;
php date
Moderator: General Moderators
Re: php date
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.
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
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 querymickd wrote:strtotime can convert your mysql time into a PHP timestamp, and then add 36000 (10*60*60) seconds to it.
Code: Select all
$final_stamp = strtotime('+10 hours',$row['unix_timestamp']);Real programmers don't comment their code. If it was hard to write, it should be hard to understand.