-1

I've come across a date format like this:

8/17/18 19:00 which corresponds to August 17th, 2018.

I tried parsing this with:

  1. pendulum.parse(date) --> returns all sorts of mixed dates when day is less than 12
  2. datetime.datetime.strptime(date, '%m/%d/%Y') --> %m goes 01 to 12, not this case

What is the correct way to parse this completely arbitrary date format ?

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
PepperoniPizza
  • 8,842
  • 9
  • 58
  • 100
  • 1
    It's not arbitrary. Looks like an American military format. – wjandrea Apr 17 '19 at 16:36
  • 3
    Possible duplicate of [Parsing non-zero padded timestamps in Python](https://stackoverflow.com/questions/25279993/parsing-non-zero-padded-timestamps-in-python) – Mark Apr 17 '19 at 16:38

1 Answers1

4

Match the number of digits in the year (%y), and include the hours and minutes (%H:%M).

>>> import datetime
>>> date = '8/17/18 19:00'
>>> datetime.datetime.strptime(date, '%m/%d/%y %H:%M')
datetime.datetime(2018, 8, 17, 19, 0)
wjandrea
  • 28,235
  • 9
  • 60
  • 81