You can use strtotime()
to convert the time to an integer, and then do a conditional.
// Get the current time
$now = strtotime("now");
// Convert post's modification time to int
$postUpdated = strtotime( $post->post_modified );
// Check if 3 hours has passed, each hour is 60*60 seconds
if ( $now - $postUpdated >= 3*60*60 ) {
// First conditional
} else {
// Second conditional
}
Also, if the time’s format is known ( which is usually 0000-00-00 00:00:00 ), you can directly use strftime()
. Here is a quick example:
$timestamp = strftime("%Y-%m-%d %h:%M:%S %a", time() - 3*60*60);
Now you have a formatted value of 3 hours before, which you can use in date_diff()
.