// dates & times reference

SQL DATEFROMPARTS function

Returns a date from three integers. SQL Server has DATEFROMPARTS; PostgreSQL has make_date; MySQL, SQLite and Oracle rebuild from strings.

카테고리
Dates & times
Returns
date
In this category
22 of 121

구문

DATEFROMPARTS(year, month, day)  -- SQL Server
MAKE_DATE(year, month, day)  -- PostgreSQL

Each block is a separate form. The support table and the examples show which engine takes which.

엔진 지원

엔진Support메모
SQL Server 예 Supported under this name.
PostgreSQL Different name or syntax make_date(year, month, day)
MySQL Different name or syntax no direct form; MAKEDATE uses day-of-year, or STR_TO_DATE
SQLite Different name or syntax build a string and pass it to date()
Oracle Different name or syntax TO_DATE(year || '-' || month || '-' || day, 'YYYY-MM-DD')

예시

SQL Server

SELECT DATEFROMPARTS(2024, 2, 29) AS leap_day;

PostgreSQL

SELECT make_date(2024, 2, 29) AS leap_day;

Oracle

SELECT TO_DATE('2024-02-29', 'YYYY-MM-DD') AS leap_day FROM dual;

알아 두면 좋은 정보

  • Invalid parts such as February 30 raise an error on SQL Server, PostgreSQL and Oracle. SQLite rolls date('2024-02-30') over to 2024-03-01 without complaint, and MySQL's STR_TO_DATE returns NULL.
  • MySQL's MAKEDATE is not month-and-day: it takes day-of-year, so MAKEDATE(2024, 61) is March 1, not January 61.
  • DATEFROMPARTS returns NULL when any argument is NULL, so a missing month in the source data becomes a missing date rather than an error.

Questions about DATEFROMPARTS

What happens with an invalid date like February 30?

SQL Server, PostgreSQL and Oracle raise an error. MySQL's STR_TO_DATE returns NULL in a SELECT (and errors inside an INSERT under strict mode); SQLite silently moves it to March 1.

Is DATEFROMPARTS the same as make_date?

Yes, same inputs and result. PostgreSQL spells it make_date; MySQL, SQLite and Oracle have no equivalent and need string building.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.