Answer the question
In order to leave comments, you need to log in
How to make a multiple of 5 minutes in Datetime?
I receive time from other sites in this format
HH:MM DD/MM/YYYY
$advanceDeliveryDate="20:13 05/06/2018";
$order_date = DateTime::createFromFormat('H:i d/m/Y', $advanceDeliveryDate);
$save['OrderDate']=$order_date->format("Y-m-d H:i:s");
($number%5)?$number-$number%5+5:$number
Answer the question
In order to leave comments, you need to log in
But as practice has shown, this does not work when the time is 20:59
$advanceDeliveryDate="20:59 05/06/2018";
$order_date = DateTime::createFromFormat('H:i d/m/Y', $advanceDeliveryDate);
$minutes = $order_date->format('i');
if ($minutes % 5)
{
$add = 5 - ($minutes % 5);
$order_date->modify("+{$add} minutes");
}
var_dump($order_date);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question