A
A
axel2017-11-11 01:48:20
css
axel, 2017-11-11 01:48:20

How to determine which time interval the current time belongs to?

There are some blocks of data tied to a specific time. Let's say the data is for 04:00, 10:00, 16:00, 22:00. And so daily. How to determine that the current time is 01:47 - closer to 04:00, but already by 04:00 the next day?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Dugin, 2017-11-11
@Antoine

timestamp // 86400
timestamp % 86400

Or use datetime objects , specifically datetime.day.

A
Alexander Taratin, 2017-11-11
@Taraflex

Add additional interval = first interval + 24 hours (28 hours in your case).
Get the number of seconds since the beginning of the day.
Determine the next interval.
If the found interval is the last one. That means moving on to the next day.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question