I can create datetime objects in python this way:
import datetime new_date= datetime.datetime(2012,09,16)
How can I create same datetime
object from a string in this format: "16SEP2012"
?
To create a date, we can use the datetime() class (constructor) of the datetime module. The datetime() class requires three parameters to create a date: year, month, day.
The date column is indeed a string, which—remember—is denoted as an object type in Python. You can convert it to the datetime type with the . to_datetime() method in pandas .
Timezone aware object using datetime now(). time() function of datetime module. Then we will replace the value of the timezone in the tzinfo class of the object using the replace() function. After that convert the date value into ISO 8601 format using the isoformat() method.
Use datetime.datetime.strptime
:
>>> datetime.datetime.strptime('16Sep2012', '%d%b%Y') datetime.datetime(2012, 9, 16, 0, 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With