Most efficient way to convert datetime string (Jul 25, 2016 11:51:32 PM) into another string (YYYYMMDD) in python -
i have string representing datetime such : "jul 19, 2016 4:45:57 pm"
i convert following string: "20160725"
what efficient way in python?
thanks :)
note : need in order input date csv file later on, used show line chart.
you can use strptime
, strftime
methods of datetime
module. following want:
from datetime import datetime dt s = "july 25, 2016 - 11:51:32 pm" old_format = '%b %d, %y - %h:%m:%s %p' new_format = '%y%m%d' r = dt.strptime(s, old_format).strftime(new_format) print(r) # '20160725'
Comments
Post a Comment