-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
3
  • none in stackoverflow.com/questions/2803852/… solved my problem. please read my question again. Commented Mar 25, 2017 at 11:39
  • What precisely is missing? You have to write the correct format string, but SO isn't here to spoon feed you. Commented Mar 25, 2017 at 11:47
  • the accepted answer to this question is what is missing, have a good day sir. Commented Mar 25, 2017 at 12:18

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.