DAY

DAY(expr)

Description

The DAY function is used to extract the day of the month from a given date or timestamp expression expr. This function works correctly for both date and timestamp types of data, returning an integer value that represents the day of the month.

Parameter Description

  • expr: date or timestamp_ltz type, representing the input date or timestamp.

Return Result

Returns an integer representing the day of the month of the input date or timestamp.

Usage Example

  1. Extract the day from a specific date:
    SELECT DAY('2022-03-31');
    +---------------------+
    | `DAY`('2022-03-31') |
    +---------------------+
    | 31                  |
    +---------------------+

The result will return 31, indicating that '2022-03-31' is the 31st day of March.

  1. Extract the day from a timestamp and combine it with other operations:
    SELECT DAY(CURRENT_TIMESTAMP()) + 5 AS target_day;
    +------------+
    | target_day |
    +------------+
    | 26         |
    +------------
  2. Compare two dates to determine if they are on the same day:
    SELECT (DAY('2022-03-31') = DAY('2022-03-01')) AS is_same_day;
    +-------------+
    | is_same_day |
    +-------------+
    | false       |
    +-------------+