SQL ROUND date function
Rounds a date to the nearest boundary of the mask's unit (the only major engine with a date-rounding function).
- 카테고리
- Dates & times
- Returns
date- In this category
- 87 of 121
구문
ROUND(date)
ROUND(date, fmt)
Each block is a separate form. The support table and the examples show which engine takes which.
엔진 지원
| 엔진 | Support | 메모 |
|---|---|---|
| SQL Server | Not built in | No built-in equivalent. |
| PostgreSQL | Not built in | No built-in equivalent. |
| MySQL | Not built in | No built-in equivalent. |
| SQLite | Not built in | No built-in equivalent. |
| Oracle | 예 | Supported under this name. |
예시
Oracle
SELECT ROUND(TO_DATE('2026-08-15 13:00', 'YYYY-MM-DD HH24:MI')) FROM dual; -- 2026-08-16
Oracle
SELECT ROUND(TO_DATE('2026-08-15 11:00', 'YYYY-MM-DD HH24:MI')) FROM dual; -- 2026-08-15
Oracle
SELECT ROUND(SYSDATE, 'Q') FROM dual; -- nearest quarter start
알아 두면 좋은 정보
- With no mask, the noon rule applies: times before 12:00 round to that day's midnight, 12:00 and after to the next day's.
- ROUND(d, 'MM') rounds up from the 16th day whatever the month's length: 2026-02-15 gives 2026-02-01 and 2026-02-16 gives 2026-03-01. 'YYYY' rounds up from July 1, 'Q' from the 16th day of the quarter's second month.
- No other engine has this: PostgreSQL's date_trunc floors only, and SQL Server's DATETRUNC does not round at all.
Questions about ROUND (date)
When is ROUND(date) actually useful?
When a value should count toward the nearest day or month rather than the one it started in, such as a shift starting at 23:40 billed to the next day. For reporting periods, TRUNC is almost always what you meant.
How do I replicate ROUND elsewhere?
TRUNC(d + 0.5) in Oracle does the day case; on PostgreSQL date_trunc('day', d + interval '12 hours').
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: Oracle.
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.