Python Date


Dates and Times

For using dates and times you need to import the datetime module. There are two types of date and time objects: naive and aware. The objects that are timezone aware are the most used.

Examples

Extract date

	
>>> from datetime import date
>>> current_date = date.today()
>>> current_date
datetime.date(2015, 3, 3)
>>> 

Extract year from date

>>> import datetime
>>> current_year = datetime.date.today().year
>>> current_year
2015
>>> 

Extract month from date

>>> import datetime
>>> current_month=datetime.date.today().month
>>> current_month
3
>>> 

Extract day from date

>>> import datetime
>>> current_day = datetime.date.today().day
>>> current_day
3
>>>