Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to only return the date part from datetime.datetime type?

date= dateutil.parser.parse('20150327T034556Z') 

returns:

2015-03-27 03:45:56+00:00

How to get the date part without the time part: (2015-03-27)

like image 856
farah Avatar asked Dec 20 '22 05:12

farah


1 Answers

There is a date method for datetime objects.

>>> date = dateutil.parser.parse('20150327T034556Z')
>>> date
datetime.datetime(2015, 3, 27, 3, 45, 56, tzinfo=tzutc())
>>> date.date()
datetime.date(2015, 3, 27)

See https://docs.python.org/2/library/datetime.html.

like image 73
lazappi Avatar answered Dec 22 '22 01:12

lazappi