Functions for Working with Dates and Times
Most functions in this section accept an optional time zone argument, e.g. Europe/Amsterdam. In this case, the time zone is the specified one instead of the local (default) one.
Example
SELECT
    toDateTime('2016-06-15 23:00:00') AS time,
    toDate(time) AS date_local,
    toDate(time, 'Asia/Yekaterinburg') AS date_yekat,
    toString(time, 'US/Samoa') AS time_samoa
┌────────────────time─┬─date_local─┬─date_yekat─┬─time_samoa──────────┐
│ 2016-06-15 23:00:00 │ 2016-06-15 │ 2016-06-16 │ 2016-06-15 09:00:00 │
└─────────────────────┴────────────┴────────────┴─────────────────────┘
makeDate
Creates a Date
- from a year, month and day argument, or
- from a year and day of year argument.
Syntax
makeDate(year, month, day);
makeDate(year, day_of_year);
Alias:
- MAKEDATE(year, month, day);
- MAKEDATE(year, day_of_year);
Arguments
- year— Year. Integer, Float or Decimal.
- month— Month. Integer, Float or Decimal.
- day— Day. Integer, Float or Decimal.
- day_of_year— Day of the year. Integer, Float or Decimal.
Returned value
- A date created from the arguments. Date.
Example
Create a Date from a year, month and day:
SELECT makeDate(2023, 2, 28) AS Date;
Result:
┌───────date─┐
│ 2023-02-28 │
└────────────┘
Create a Date from a year and day of year argument:
SELECT makeDate(2023, 42) AS Date;
Result:
┌───────date─┐
│ 2023-02-11 │