Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add 1 hour on mysql timestamp in php

Tags:

php

In my Mysql table I have a timestamp field. In my php page I show the record ($row[data]) in this way

echo date("d-m-Y H:i:s", strtotime($row['data']));

Now in my php I'd like to add 1 hour on my date. How can I do this? Thanks

like image 745
Paolo Rossi Avatar asked Feb 22 '13 14:02

Paolo Rossi


3 Answers

echo date("d-m-Y H:i:s", strtotime($row['data'])+3600);

note that you can't compare resulting dates in "d-m-Y" format.

either compare strtotime results or initial dates. or format your results into proper format first.

like image 170
Your Common Sense Avatar answered Sep 26 '22 00:09

Your Common Sense


You could do this straight away in MySQL:

SELECT `date` + INTERVAL 1 HOUR AS `date`
FROM ...
like image 34
Ja͢ck Avatar answered Sep 27 '22 00:09

Ja͢ck


         echo date("d-m-Y H:i:s", strtotime($row['data'].' +1 hour'));
like image 29
mohan.gade Avatar answered Sep 24 '22 00:09

mohan.gade