How do I convert a string to a date object in python?
The string would be: "24052010"
(corresponding to the format: "%d%m%Y"
)
I don't want a datetime.datetime object, but rather a datetime.date.
How do I convert a string to a date object in python?
The string would be: "24052010"
(corresponding to the format: "%d%m%Y"
)
I don't want a datetime.datetime object, but rather a datetime.date.
you have a date string like this, "24052010" and you want date object for this,
this cus_date will give you date object.
you can retrieve date string from your date object using this,
If you are lazy and don't want to fight with string literals, you can just go with the
parser
module.Just a side note, as we are trying to match
any
string representation, it is 10x slower thanstrptime
Use time module to convert data.
Code snippet:
There is another library called
arrow
really great to make manipulation on python date.You can use
strptime
in thedatetime
package of Python: