Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add 13 hours to a timestamp

Tags:

php

time

I have a table with timestamp values like:

    2009-07-14 02:00:00

I need to display them at run time with 13 hours added, like:

    2009-07-14 15:00:00

What's the simplest way to do this in PHP?

like image 911
aalaap Avatar asked Jul 14 '09 11:07

aalaap


People also ask

How do you add 24 hours to a timestamp?

echo time() + (24*60*60);

How do I add hours to a timestamp in SQL?

We can use DATEADD() function like below to add hours to DateTime in Sql Server. DATEADD() functions first parameter value can be hour or hh all will return the same result.

How do I add hours to a DateTime?

The DateTime. AddHours() method in C# is used to add the specified number of hours to the value of this instance. This method returns a new DateTime.


1 Answers

I know that

date( "Y-M-d H:i:s", strtotime( $timestamp_from_array ) + 13 * 3600 );

is smelly, but it will give you an idea.

strtotime converts the timestamp string to a timestamp value, then we add the hours and convert it back to the timestamp format in the array with the date function.

But I suppose what you really want is to use time zones.

Edit: igstan is correct, you should also mind the daylight saving time changes between those offsets.

like image 98
macbirdie Avatar answered Sep 20 '22 20:09

macbirdie