Finding difference between date now and last comment I want users to wait 9 minutes after their last comment. I have written this code. It works but do you think this is practical? Is there a simpler solution?  

$now = new DateTime( date( 'Y-m-d H:i:s' ) );
$lastPost = new DateTime( '2016-01-08 13:16:59' );
$diff = $lastPost-&gt;diff( $now );

if ( $diff-&gt;format( '%Y-%m-%d %H' ) == '00-0-0 00' ) {
    if ( $diff-&gt;format( '%i' ) &lt; 9 ) {
         echo $diff-&gt;format( '%i minuts left or ahead' );
    }
}
Current time is easily obtained simply with new DateTime(), no need to specify any formatting (default is now). Also you don't need to format dates to compare strings because DateTime itself is comparable. All together:

$now = new DateTime();
$lastPostTime = new DateTime('2016-01-08 13:16:59');
$notEnabledBefore = lastPostTime-&gt;add(new DateInterval('PT9M'));

if (now &lt; notEnabledBefore) {
    $timeToWait = notEnabledBefore-&gt;diff(now);
    echo $timeToWait-&gt;format('%i minutes left or ahead');
}