I have to transform a string 'yesterday 14:56' to string '19 july 2020 14:56'.
if it is 'today 13:20', it must be string '20 july 2020 13:20'.
i have a function:
new_dates =[
['yesterday', '18:27'],
['today', '01:47'],
['yesterday', '21:45'],
['yesterday', '20:52'],
['yesterday', '19:48'],
['yesterday', '17:34'],
['yesterday', '14:50']]
from datetime import datetime as dd
import datetime as dt
for d in new_dates:
if d[0] == 'yesterday':
date = dd.strptime(d[1], '%H:%M')
t = date.strftime('%H:%M')
t = t.split(':')
hours = int(t[0])
minutes = int(t[1])
today = dt.date.today()
yesterday = today - dt.timedelta(days=1, hours=hours, minutes=minutes)
print( yesterday)
yesterday should have '2020-07-19 13:20'
but it only shows the date '2020-07-19' without hours & minutes.