Python Dates

In python, it is done using the DateTime module.

First, need to import datetime module:

>>> Import datetime

>>> print(datetime.now())

Displaying current Date and Time:

>>>  datetime.date.today()

It displays the current date.

>>>  print(datetime.date(2019, 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

Example:

import datetime

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

print(x)

 

Output:

2019-06-10 00:00:00

strftime() method

It used to specify the formate of given datetime.

 

Example:

import datetime

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

print(x.strftime("%B"))

 

Output:

It returns the month:

June

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 –

https://docs.python.org/3/library/datetime.html

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