Reputation: 1978
I have the following string which represents a date: '20200317'
(yyyyMMdd). Is there any way to pass this string directly to a date object in python? Or I'll have to "break" this string into the year, month and day and then pass it to the date object?
Upvotes: 2
Views: 40
Reputation: 312219
You could use datetime.strptime
:
from datetime import datetime
datetimeObject = datetime.strptime('20200317', '%Y%m%d')
Upvotes: 4