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

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -