PHP - Strtotime - Add hours

TheLettuceMaster picture TheLettuceMaster · Jun 18, 2012 · Viewed 49.6k times · Source

I have this variable:

$timestamp = strftime("%Y-%m-%d %h:%M:%S %a", time ());

I simply want to add three hours and echo it out.

I have seen the way where you can do the 60 * 60 * 3 method or the hard code "+ 3 hours" where it understands the words.

What is the best way of getting this result?

Answer

Ja͢ck picture Ja͢ck · Jun 18, 2012

The best way is what you think is more readable. The following expressions are identical:

time() + 3 * 60 * 60

strtotime('+3 hours')