Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert string to datetime in python [duplicate]

Tags:

python

I have a date string in following format 2011-03-07 how to convert this to datetime in python?

like image 670
shaan Avatar asked Mar 07 '11 12:03

shaan


1 Answers

Try the following code, which uses strptime from the datetime module:

from datetime import datetime
datetime.strptime('2011-03-07','%Y-%m-%d')

I note that this (and many other solutions) are trivially easy to find with Google ;)

like image 62
Mark Longair Avatar answered Nov 11 '22 15:11

Mark Longair