Reputation: 762
[datetime.datetime(2015, 6, 23, 0, 0), datetime.datetime(2015, 6, 24, 0, 0)]
to
[datetime.datetime(2015, 6, 23, 0, 0).date(), datetime.datetime(2015, 6, 24, 0, 0).date()]
so I can have this:
[datetime.date(2015, 6, 23), datetime.date(2015, 6, 24)]
Upvotes: 3
Views: 3434
Reputation: 117856
You can invoke the date
method on each datetime
object within a list comprehension. If your list of datetime
objects was named l
, then for example you could do the following
>>> [i.date() for i in l]
[datetime.date(2015, 6, 23), datetime.date(2015, 6, 24)]
Upvotes: 2
Reputation: 820
You can do this by using a list comprehension.
my_date_list = [d.date() for d in my_datetime_list]
Upvotes: 5