vastorbit.sql.functions.round_date¶
- vastorbit.sql.functions.round_date(expr: Annotated[str | list[str] | StringSQL | list[StringSQL], ''], precision: str = 'DD') StringSQL¶
Rounds the specified date or time.
- Parameters:
expr (SQLExpression) – Expression.
precision (str, optional) –
A string constant that specifies precision for the rounded value, one of the following:
- Century:
CC | SCC
- Year:
SYYY | YYYY | YEAR | YYY | YY | Y
- ISO Year:
IYYY | IYY | IY | I
- Quarter:
Q
- Month:
MONTH | MON | MM | RM
- Same weekday as first day of year:
WW
- Same weekday as first day of ISO year:
IW
- Same weekday as first day of month:
W
- Day (default):
DDD | DD | J
- First weekday:
DAY | DY | D
- Hour:
HH | HH12 | HH24
- Minute:
MI
- Second:
SS
Note
On Trino,
Century,ISO Yearand the weekday-aligned codes (WW,IW,W) have no native equivalent and raiseNotImplementedError.
- Returns:
SQL string.
- Return type:
StringSQL
Examples
First, let’s import the VastFrame in order to create a dummy dataset.
from vastorbit import VastFrame
Now, let’s import the vastorbit SQL functions.
import vastorbit.sql.functions as vof
We can now build a dummy dataset.
df = VastFrame({"x": ['1993-11-03', '1959-09-09']}) df["x"].astype("date")
Now, let’s go ahead and apply the function.
df["round_x"] = vof.round_date(df["x"], 'MM') display(df)
📅xDate📅round_xDate1 1959-09-09 1959-09-01 2 1993-11-03 1993-11-01 Note
It’s crucial to utilize vastorbit SQL functions in coding, as they can be updated over time with new syntax. While SQL functions typically remain stable, they may vary across platforms or versions. vastorbit effectively manages these changes, a task not achievable with pure SQL.
See also
VastFrame.eval(): Evaluates the expression.