I have Googled and I give up, here goes...
I have always had issues dealing with times/timestamps etc, I am trying to pull a date from my database in SQL TIMESTAMP format, this is what I have so far...
$db = $row_rsSearch['created_date'];
$newdate = date("d/m/Y H:i:s", strtotime('+3 hours', $db));
What is wrong with it? I am getting a return of "31/12/1969 20:33:34" when the database is providing... 2014-04-25 02:19:53
Thanks in advance.
Use DateTime::createFromFormat
and DateTime::add
$date = DateTime::createFromFormat('Y-m-d H:i:s', '2014-04-25 02:19:53');
$date->add(new DateInterval('PT3H'));
echo $date->format("d/m/Y H:i:s");
strtotime takes a timestamp when you use it to calculate a new timestamp. In your case:
$newdate = date("d/m/Y H:i:s", strtotime('+3 hours', strtotime($db)));
Great, thanks!
For other users, this is my completed code (8 hours added on)
$db = $row_rsSearch['created_date'];
$date = DateTime::createFromFormat('Y-m-d H:i:s', $db);
$date->add(new DateInterval('PT8H'));
If I got it right you want to add 3 hours to each date?
Why don't you do it within query?
example:
SELECT `date` + INTERVAL 3 HOUR AS created_date FROM `TABLE`
Can try this too:
$db = $row_rsSearch['created_date'];
$newdate = date("d/m/Y H:i:s", strtotime($db.'+3 hours'));