Python Dates

In python, it is done using the DateTime module.

First, need to import datetime module:

>>> Import datetime

>>> print(

Displaying current Date and Time:


It displays the current date.

>>>  print(, 4, 13))

It displays the date in proper formate.

How to creating a datetime object?

To creating datetime object we use "datetime" class with "datetime" module


import datetime

x = datetime.datetime(2019, 6, 10)




2019-06-10 00:00:00

strftime() method

It used to specify the formate of given datetime.



import datetime

x = datetime.datetime(2019, 6, 10)




It returns the month:


List of other strftime() codes

%A - Use for weekday short format

%a -  Weekday without abbreviation

%w - Weekday in number format(0-6), where 0 is used for Sunday

%d - Use for the day of the month(0-31)

%b - Use for month name with the abbreviation, for example - dec

And more others.

You can read complete datetime using python doc –

Contact Us

Tel: (+91) 0120  4118730  

Time :   10 : 00  AM -  08 : 00 PM IST 

Registered address: G-69, Sector 63, 

 Noida - 201301, India

We Provide Services Across The different countries

USA    Australia   Canada   UK    UAE    Singapore   New Zealand    Malasia   India   Ireland   Germany

CodersArts is a Product by Sofstack Technology Solutions Pvt. Ltd.

  • CodersArts | Linkedin
  • Instagram