V
V
Valery Khizhevsky2018-05-10 12:20:59
PHP
Valery Khizhevsky, 2018-05-10 12:20:59

How to round up time to a smaller value?

Good afternoon, the task is: "Select data for the chart, with an interval of 15 minutes." The beginning of the chart should start from some specific date, for example (9:00, or 9:15, or 9:30). And how can I now, for example, 9:48 come to 9:45?
Are there any native methods in php or mysql, or can this be done using Carbon (Laravel framework)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniel, 2018-05-10
@Roshette

$now = \Carbon\Carbon::now();
$now->minute($now->minute - $now->minute % 15)->second(0)

J
Jim_Di, 2018-05-10
@JimDi

www.sql.ru/forum/689900/funkciya-okrugleniya-vremeni - discussion of a similar problem and several solutions, there are similar to Daniel 's solution but immediately in sql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question