Trouble Using Datetime.strptime()
I have an Excel spreadsheet. I am trying to capture a line from the Excel sheet that contains a date, then parse the date out with datetime.strptime(). Here is the bit of the Exce
Solution 1:
You need to modify the regex you're using to get the date from the Excel file.
pattern = re.compile(r'Listing ([A-Z]+ \d{1,2} \d{4})', re.IGNORECASE)
[A-Z]+
means "one or more capital letters", \d{1,2}
means "one or two numbers" and \d{4}
means "four numbers".
Furthermore the format of date you're using is incorrect - %w
means weekday (numbers from 0 to 6 representing weekdays from Sunday to Saturday), while you should use %d
which matches day of the month
So it should look like this in the end:
datetime_object = datetime.strptime(new_a, '%b %d %Y')
Post a Comment for "Trouble Using Datetime.strptime()"