User Tools

Site Tools


convert_string_to_date

This is an old revision of the document!


single date; without pandas

Use

from datetime import datetime
datetime.strptime(date_str, date_fmt).date()

Example:

$ ipython
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]:
from datetime import datetime
s = '24 October 2022'
dt = datetime.strptime(s, '%d %B %Y').date()

In [2]:
print(dt)
2022-10-24

In [3]:
type(dt)
Out[3]:
datetime.date
convert_string_to_date.1669610129.txt.gz · Last modified: 2022/11/28 04:35 by raju