SYSDATETIME (Transact‑SQL)
The SYSDATETIME()
function returns the current system date and time as a datetime2
value with a precision of 100 nanoseconds.
Syntax
SYSDATETIME ( )
Return type
datetime2(7)
Remarks
- The returned value reflects the operating system's date and time.
- It is not affected by the
SET DATEFIRST
orSET LANGUAGE
settings. - For UTC values, use
SYSUTCDATETIME()
. - To get just the date part, use
CAST(SYSDATETIME() AS date)
.
Examples
-- Example 1: Retrieve the current date and time
SELECT SYSDATETIME() AS CurrentDateTime;
-- Example 2: Get the date part only
SELECT CAST(SYSDATETIME() AS date) AS CurrentDate;
-- Example 3: Format as ISO 8601 string
SELECT CONVERT(varchar(33), SYSDATETIME(), 126) AS ISO8601String;