round_date

In [ ]:
round_date(expr, 
           precision: str = 'DD')

Rounds the specified date or time.

Parameters

Name Type Optional Description
expr
object
❌
Expression.
precision
str
✓
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

str_sql : SQL expression.

Example

In [1]:
from verticapy import *
df = tablesample({"x": ['11/03/1993', '09/05/1959']}).to_vdf()
df["x"].astype("date")
display(df)
📅
x
Date
11993-11-03
21959-09-05
Rows: 1-2 | Column: x | Type: date
In [2]:
# Importing the stats module
import verticapy.stats as st

# Applying the round_date function
df["round_x"] = st.round_date(df["x"], 'MM')
display(df)
📅
x
Date
📅
round_x
Datetime
11993-11-031993-11-01 00:00:00
21959-09-051959-09-01 00:00:00
Rows: 1-2 | Columns: 2