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?
echo time() + (24*60*60);
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With