Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

I can see a lot of changing over a date string to a DateTime object in Python, however I need to go the alternate way. 

I have 

datetime.datetime(2012, 2, 23, 0, 0)

also, I might want to change it over to string like '2/23/2012'.

1 Answer

0 votes
by (26.4k points)

Try using strftime, which will help you to format your date

For example:

import datetime

t = datetime.datetime(2012, 2, 23, 0, 0)

t.strftime('%m/%d/%Y')

output:

'02/23/2012'

Click on this link for more information.

Interested to learn python in detail? Come and Join the python course.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...