Display Expire time in Days, Hours, Minutes and Seconds



<?php
date_default_timezone_set('Asia/Calcutta');
function datediff( $date1, $date2 )
{
$diff = abs( strtotime( $date1 ) - strtotime( $date2 ) );

return sprintf
(
"%d Days, %d Hours, %d Mins, %d Seconds",
intval( $diff / 86400 ),
intval( ( $diff % 86400 ) / 3600),
intval( ( $diff / 60 ) % 60 ),
intval( $diff % 60 )
);
}

print datediff( "2015-05-11 14:55:00", "now" ) . "\n";
Advertisements

How to show page load time in PHP ?


If you need to calculate how much time elapsed during this the queries execute on the page.

The answer is:

$start = microtime(true);
$end = microtime(true);
printf("Page was generated in %f seconds", $end - $start);

For reference, microtime() in a PHP predefined function.

Write $start just before your query or the beginning of the page and $end at the end of all the queries or at the end of page.