-3

E.G. If I want current date with 15 minute leap: If now is :

2017-2-2 18:22

15 minute leap time will be :

2017-2-2 18:30

If now is :

2017-2-2 18:30

15 minute leap time will be :

2017-2-2 18:30

If now is :

2017-2-2 18:31

15 minute leap time will be :

2017-2-2 18:45

15:01 to 30:00 gives 30:00, 30:01 to 45:00 gives 45:00 etc...

Machavity
  • 30,841
  • 27
  • 92
  • 100
fico7489
  • 7,931
  • 7
  • 55
  • 89

1 Answers1

-1

Solution is :

public function minutesToQuarterHour($timestring) {
    $minutes = date('i', strtotime($timestring));
    return ($minutes - ($minutes % 15) + 15);
}

$time = '2016-10-04 15:59:00'; ///or any date get with carbon->now()
$minutes = minutesToQuarterHour($time);
$dateBase = Carbon::parse($time);
$dateBase = Carbon::parse($dateBase->format("Y-m-d H" . ':00:00'))->addMinutes($minutes);
echo $dateBase->format("Y-m-d H:i");
fico7489
  • 7,931
  • 7
  • 55
  • 89
  • 3
    I don't get it why you make it so complicated? `$now = \Carbon\Carbon::now(); $now->addMinutes(15);` also do the trick – Sebastian Feb 14 '17 at 10:50
  • first I detect minutes addition, then I produce now time but hourly based, e.g. 2017 2-2 15:00:00 than I add minutes on this time... – fico7489 Feb 14 '17 at 11:04