onenonly Posted June 17, 2009 Share Posted June 17, 2009 I get datetime from mysql in this format 2009-06-17 13:51:01 when I get that from mysql I want to add 2 hours $row = mysql_fetch_array($result); echo $row[date]; echo $row[date] + 2 hours; ???? Link to comment https://forums.phpfreaks.com/topic/162609-datetime-mysql-php/ Share on other sites More sharing options...
947740 Posted June 17, 2009 Share Posted June 17, 2009 You forgot apostrophes. Anyway... Do strtotime first. $date = strtotime($row['date'] + 2 hours); And then reformat it using date(). Link to comment https://forums.phpfreaks.com/topic/162609-datetime-mysql-php/#findComment-858196 Share on other sites More sharing options...
onenonly Posted June 18, 2009 Author Share Posted June 18, 2009 it doesnt work??? <?php $time = "2009-06-17 13:51:01"; $test = strtotime($time + "2 hours"); echo $test."<BR>"; echo $time."<BR>"; echo date("Y-m-j H:i:s", $test); ?> output: 1245287460 2009-06-17 13:51:01 2009-06-17 20:11:00 <-----WRONG it suppose to be 2009-06-17 15:51:01 Link to comment https://forums.phpfreaks.com/topic/162609-datetime-mysql-php/#findComment-858565 Share on other sites More sharing options...
Ken2k7 Posted June 18, 2009 Share Posted June 18, 2009 Why not add 2 hours using SQL? SELECT DATE_ADD(date, INTERVAL 2 HOUR) FROM table; Link to comment https://forums.phpfreaks.com/topic/162609-datetime-mysql-php/#findComment-858568 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.