How to round up my given time is to the last 15 minutes?
Example values are given below.
07:17:46 need to be 07:15:00
06:25:25 need to be 06:15:00
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
We want to connect the people who have knowledge to the people who need it, to bring together people with different perspectives so they can understand each other better, and to empower everyone to share their knowledge.
Ryan Cooper
Split into hours, minutes and seconds. Round the minutes down, fill with zeros and return.
function timeLastQuarter($timestr) {
$time = explode(":",$timestr);
return str_pad($time[0],2,"0",STR_PAD_LEFT).":".str_pad(((floor($time[1] / 15))*15),2,"0",STR_PAD_LEFT).":00";
}
Example:
echo timeLastQuarter("15:55:00");