I need the date calculation in Python => Midnight from the previous day to the current time of day -


i need date calculation in python => midnight previous day current time of day.

sample:

current date        transformation 28/07/2017 17:00 => 26/07/2017 23:59:59  26/07/2017 16:00 => 24/07/2017 23:59:59  

attempted code , not work.

code

import datetime days_ago = datetime.datetime.now() + datetime.timedelta(days=-1) 

you started well. change hour minute , second:

import datetime days_ago = datetime.datetime.now() + datetime.timedelta(days=-1) days_ago = days_ago.replace(second=59, minute=59, hour=23) 

but examples might days=-2.


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -