Loading...

verticapy.sql.functions.round_date#

verticapy.sql.functions.round_date(expr: 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

Returns#

StringSQL

SQL string.

Examples#

First, let’s import the vDataFrame in order to create a dummy dataset.

from verticapy import vDataFrame

Now, let’s import the VerticaPy SQL functions.

import verticapy.sql.functions as vpf

We can now build a dummy dataset.

df = vDataFrame({"x": ['11/03/1993', '09/05/1959']})
df["x"].astype("date")

Now, let’s go ahead and apply the function.

df["round_x"] = vpf.round_date(df["x"], 'MM')
display(df)
📅
x
Date
100%
📅
round_x
Timestamp(29)
100%
11993-11-031993-11-01 00:00:00
21959-09-051959-09-01 00:00:00

Note

It’s crucial to utilize VerticaPy 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. VerticaPy effectively manages these changes, a task not achievable with pure SQL.

See also

vDataFrame.eval() : Evaluates the expression.