Example datetime constructor image mistake

Screen Link: https://app.dataquest.io/m/353/working-with-dates-and-times-in-python/5/using-strptime-to-parse-strings-as-dates

Image Link: https://s3.amazonaws.com/dq-content/353/manually_parse_date.svg

Hi there - just wanted to point out a (very minor) mistake in an image …

The code linked in the image above for an example way to manually construct a datetime object works; however for the ‘yr’ variable, it returns the integer ‘0015’. Slight OCD here, so I recreated a workaround for this example below. Simply adds 2000 to the ‘yr’ integer because the dataset started in 2009, so we won’t have any values before the year 2000.

date_string = '12/18/15 16:30'
date, time = date_string.split()

hr, mn = time.split(':')
mnth, day, yr = date.split('/')

hr = int(hr)
mn = int(mn)
mnth = int(mnth)
day = int(day)
yr = 2000 + int(yr)

date_dt = dt.datetime(yr, mnth, day, hr, mn)
print(date_dt)

You can provide feedback on content issues like these directly to DQ through the ? button in the top-right corner of the Mission Step page and report it to them. They can then look into it accordingly.

1 Like

Thanks! removing from here now.