Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google app engine datastore datetime to date in Python?

I've always hated the headache of managine dates, times, datetimes, and the various formats and conversions that are needed with them. I'm taking an online course on using the google app engine and it says to use the datetime property, which is returning a date in the format:

2012-06-25 01:17:40.273000

I tried

datetime.strptime('2012-06-25 01:17:40.273000','%y-%m-%d %H:%M:%S')

but it didn't work..

I just want to extract the 2012-06-25 part without using a hacky regex or string slicing solution.

How do I parse this and convert it to the proper format?

like image 420
mowwwalker Avatar asked Dec 26 '22 22:12

mowwwalker


1 Answers

Finally found it (shortly after asking the question, but I've been trying for the past hour)

datetime.strptime('2012-06-25 01:17:40.273000','%Y-%m-%d %H:%M:%S.%f')

What I wanted:

datetime.strptime('2012-06-25 01:17:40.273000','%Y-%m-%d %H:%M:%S.%f').strftime('%m-%d-%Y')
like image 188
mowwwalker Avatar answered Jan 23 '23 00:01

mowwwalker