Issue
from datetime import timedelta, date
def daterange(date1, date2):
for n in range(int ((date2 - date1).days)+1):
yield date1 + timedelta(n)
start_dt = date(2015, 12, 20)
end_dt = datetime.now()
for dt in daterange(start_dt, end_dt):
print(dt.strftime("%Y%m%d"))
I want to print all the dates between start_dt and current date.
Here's the error:- unsupported operand type(s) for -: 'datetime.datetime' and 'datetime.date'
Solution
An alternative solution to your problem is using pandas
import pandas as pd
pd.date_range(start=start_date,end=end_date)
Answered By - Akash garg
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.