0

I want to convert a datestring into another date format.

The datestring

2014-11-20T00:00:00.000Z

The code

datetime.datetime.strptime(date, '%Y-%m-%dT%H:%M:%S%Z').strftime('%Y%m%d')

The error

time data '2014-11-20T00:00:00.000Z' does not match format '%Y-%m-%dT%H:%M:%S%Z'

I can read the error message but I cannot find the right format that matches the datestring.

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
Rooterle
  • 373
  • 1
  • 4
  • 12

1 Answers1

2

To include the millisecond paramater use this: datetime.datetime.strptime(d, '%Y-%m-%dT%H:%M:%S.%fZ').strftime('%Y%m%d')

Jakob
  • 1,129
  • 9
  • 24