How to add 2 hours to the wordpress time which has already been formed using current_time("mysql", false)
?
1 Answer
The WordPress current_time()
returns the current time in the format specified in the first parameter. In your example code, this is the mysql
value. The second parameter represents a timezone option. The default returns the local time for the timezone specified on the site’s Settings > General page, or GMT depending on the value supplied when calling the function.
https://codex.wordpress.org/Function_Reference/current_time
If time mathematics are still required, using the PHP strtotime()
function is useful for this:
$now = current_time( 'mysql' );
echo 'It is currently: ' . $now . '<br>';
$later = date( 'Y-m-d H:i:s', strtotime( $now ) + 7200 ); //7200 seconds = 2 hours
echo 'In 2 hours it will be: ' . $later;