Understanding the String Conversion of a Date with an English Month

Asked 3 months ago, Updated 3 months ago, 8 views

I would like to ask about string conversion of dates including English month in python.

date:10 OCT 2017

This is a character type, so I would like to convert it to a date type.

 from datetime import datetime
datetime.strptime('date', '%d%b%Y')

I am trying to convert in , but I cannot because of an error.

I would appreciate it if someone could let me know.
Thank you for your cooperation.

python3

2022-09-30 13:55

1 Answers

In your Python 3.6.1 environment, the following coding seems to work well.

If the first argument of datetime.strptime('date','%d%b%Y') really remains 'date', it is treated as a string of atedate と instead of a variable.
Alternatively, : of the code provided is a full-width character, so is this mistaken for a half-width character?
If the code below does not solve this problem, it will be easier to get a more detailed answer if you add the error as it is.

>>>from datetime import datetime
>>>date="10 OCT 2017"
>> datetime.strptime (date, '%d%b%Y')
datetime.datetime (2017, 10, 10, 0, 0)
>>>date="date:10 OCT 2017"
>> datetime.strptime (date, 'date: %d %b %Y')
datetime.datetime (2017, 10, 10, 0, 0)


2022-09-30 13:55

If you have any answers or tips


© 2023 OneMinuteCode. All rights reserved.