Reputation: 3
I am trying to generate a date with range but the time is not showing. The code is as follows:
def date_range(start, end, step: datetime.timedelta):
while start < end:
yield start
start += step
for d in date_range(
start=datetime.date(2019, 1, 1),
end=datetime.date(2019, 1, 15),
step=datetime.timedelta(days=7),
):
print(d)
>>>2019-01-01
>>>2019-01-08
The code shows the date only without the time. Why???
Upvotes: 0
Views: 38
Reputation: 128
You are using datetime.date()
which, according to the Python documentation here does not include time information - it just sets the hours/minutes/seconds to 0.
I think you want to use datetime.datetime()
which does include time information.
See the Python documentation on datetime.datetime()
for more information.
Upvotes: 1