// dates & times reference

SQL SMALLDATETIME type

A compact 4-byte type storing minutes only: seconds are dropped on assignment by rounding, not truncation.

Catégorie
Dates & times
Returns
smalldatetime
In this category
93 of 121

Syntaxe

CAST(value AS SMALLDATETIME)

Prise en charge des moteurs

MoteurSupportNotes
SQL Server Oui Supported under this name.
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 Not built in No built-in equivalent.

Exemples

SQL Server

SELECT CAST('2026-08-01 10:29:31' AS SMALLDATETIME);  -- 2026-08-01 10:30

SQL Server

SELECT CAST(SYSDATETIME() AS SMALLDATETIME);

Bon à savoir

  • Rounding is to the nearest minute: from a string or datetime, 29.998 seconds or less rounds down and 29.999 or more rounds up, so 10:29:29.998 becomes 10:29 and 10:29:29.999 becomes 10:30. A datetime2 source rounds up only from 30 seconds.
  • Range is 1900-01-01 through 2079-06-06, fine for business data, a real limit for birthdates of the very old or far-future schedules.
  • No seconds means joins and comparisons are minute-grained; equality checks that 'worked' on smalldatetime break when columns move to datetime2 with real seconds.

Questions about SMALLDATETIME

Why does anyone still use smalldatetime?

Legacy schemas and 4-byte storage. New tables should use datetime2(0): 6 bytes, whole seconds, years 0001-9999, and no rounding to the minute.

How do I mimic smalldatetime rounding elsewhere?

PostgreSQL: date_trunc('minute', d + interval '30 seconds'); Oracle: ROUND(d, 'MI'), which rounds to the nearest minute the same way.

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

Cheat sheets for the engines that have it: SQL Server.

// 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.