php round down 5 minutes time -


what correct way round down current time 5 minutes in php minus 5 minutes? need output time string, in 2 decimals in format:

$today = date("dmyhi");    

example:

16:32 -> 16:25

18:54 -> 18:45

20:04 -> 19:55

thanks lot!

try this:

$date = new datetime(); $hours = $date->format('h') $minutes = (integer) $date->format('i');  // round down nearest multiple of 5 $minutes = floor($minutes / 5 ) * 5;  // if $minutes 0 or 5 add trailing 0 if($minutes < 10) {     $minutes = '0' . $minutes; }  // output echo $hours . ':' . $minutes; 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -