0

How can i convert date from this formt "Tue May 15 2018 00:00:00 GMT-0400 (EDT)" to date in the format yyyy-mm-dd?

skr
  • 127
  • 2
  • 16
  • 2
    Possible duplicate of [Converting string into datetime](https://stackoverflow.com/questions/466345/converting-string-into-datetime) – pault May 02 '18 at 19:27

2 Answers2

4

dateutil is your friend:

>>> import dateutil.parser

>>> dt=dateutil.parser.parse('Tue May 15 2018 00:00:00 GMT-0400 (EDT)')
datetime.datetime(2018, 5, 15, 0, 0, tzinfo=tzoffset('EDT', 14400))

>>> dt.strftime('%Y-%m-%d')
'2018-05-15'
fferri
  • 18,285
  • 5
  • 46
  • 95
0

You can try:

from datetime import datetime

    date_converted = datetime.strptime(time_string, '%Y-%m-%d')


More info here, docs and here.

Chiefir
  • 2,561
  • 1
  • 27
  • 46
  • The question specifically asks for the given format. This does not work with the provided string. It would help if you adjusted the format for the one given in the question. – ambiso May 02 '18 at 19:41