Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (12.7k 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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...