Datetime¶
https://www.confessionsofadataguy.com/date-and-datetime-manipulation-in-polar
https://medium.com/@riellygriffiths/working-with-datetime-data-in-polars-9bb57e7f6304
string to date¶
df.with_columns(
dt = pl.col('dt').str.to_datetime().cast(pl.Date)
)
df.with_columns(
dt = pl.col('dt').str.strptime(pl.Date)
)
ctx = pl.SQLContext(data=df)
ctx.execute('SELECT *, CAST(dt as DATE) as date FROM data', eager=True)
ctx.execute('SELECT *, DATE(dt) as dt FROM data', eager=True)
string to datetime¶
date to string¶
date to yera/month/day¶
df.with_columns([
pl.col('dt').dt.year().alias('year'),
pl.col('dt').dt.month().alias('month'),
pl.col('dt').dt.day().alias('day'),
])