-1

I'm a Python newbie and don't how to convert a Python 3.5x string

'2017-04-19 00:23'

into a date and time like

April 19, 2017 12:23 am

and even get individual units like

April
19
2017
12:23 am

or get day of week for 4/19/217

Wednesday
mssoft123
  • 43
  • 1
  • 5
  • none in http://stackoverflow.com/questions/2803852/python-date-string-to-date-object solved my problem. please read my question again. – mssoft123 Mar 25 '17 at 11:39
  • What precisely is missing? You have to write the correct format string, but SO isn't here to spoon feed you. – jonrsharpe Mar 25 '17 at 11:47
  • the accepted answer to this question is what is missing, have a good day sir. – mssoft123 Mar 25 '17 at 12:18

1 Answers1

2

Use python datetime module, something like this :

from datetime import datetime

date_str = '2017-04-19 00:23'
date_obj = datetime.strptime(date_str, '%Y-%m-%d %H:%M')

# To get a particular part of the date in a particular format such as "Wednesday" for the "Datetime Object"
print(date_obj.strftime('%A'))

print(date_obj.strftime('%c'))

This will result in :

Wednesday
Wed Apr 19 00:23:00 2017

Check out the documentation.

Satish Prakash Garg
  • 2,213
  • 2
  • 16
  • 25