Php – Add 13 hours to a timestamp


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?

Best Solution

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.