How can I find the nearest 15 (or 10) minute interval in python ? e.g.
>>> datetime.datetime.now()
datetime.datetime(2011, 2, 22, 15, 43, 18, 424873)
I'd like the current 15 minute interval (15:30-15:44) so I'd like to transform the above datetime to a
datetime.datetime(2011, 2, 22, 15, 30, 00, 00)
Quite the easiest way to me:
from datetime import datetime, timedelta
now = datetime.now()
now = now - timedelta(minutes = now.minute % 15, seconds = now.second, microseconds = now.microsecond )
Hope that'll help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With