跳转到主要内容

TO_START_OF_MONTH

Rounds down a date or date with time (timestamp/datetime) to the first day of the month. Returns the date.

Syntax

to_start_of_month( <expr> )

Arguments

ArgumentsDescription
<expr>date/timestamp

Return Type

Datetime object, returns date in “YYYY-MM-DD” format.

Examples

SELECT to_start_of_month(to_date(18869));
+-----------------------------------+
| to_start_of_month(to_date(18869)) |
+-----------------------------------+
| 2021-08-01 |
+-----------------------------------+

SELECT to_start_of_month(to_timestamp(1630812366));
+---------------------------------------------+
| to_start_of_month(to_timestamp(1630812366)) |
+---------------------------------------------+
| 2021-09-01 |
+---------------------------------------------+