SQL Server SYSDATETIME() Function
The SQL Server (Transact-SQL) SYSDATETIME() function returns the current date and time. This function derives this value from the operating system of the computer on which the instance of SQL Server runs.
The SYSDATETIME() function returns the system date and time in the format 'yyyy-mm-dd hh:mi:ss.mmmmmmm'.
Syntax
SYSDATETIME()
Parameters
No parameter is required.
Return Value
Returns the current date and time.
Example 1:
The example below shows the usage of SYSDATETIME() function.
SELECT SYSDATETIME(); Result: '2021-12-27 05:11:57.1234567'
Example 2:
Consider a database table called EmployeeLogin with the following records:
EmpID | Name | Login Stamp |
---|---|---|
1 | John | 2019-10-25 09:20:38.4142345 |
2 | Marry | 2019-10-25 09:21:05.8545678 |
3 | Jo | 2019-10-25 09:24:35.1231232 |
4 | Kim | 2019-10-25 09:25:24.3214589 |
5 | Ramesh | 2019-10-25 09:27:16.6590012 |
To insert a new record in this table, the following statement can be used.
INSERT INTO EmployeeLogin VALUES (6, 'Suresh', SYSDATETIME()); -- see the result SELECT * FROM EmployeeLogin;
This will produce a result similar to:
EmpID | Name | Login Stamp |
---|---|---|
1 | John | 2019-10-25 09:20:38.4142345 |
2 | Marry | 2019-10-25 09:21:05.8545678 |
3 | Jo | 2019-10-25 09:24:35.1231232 |
4 | Kim | 2019-10-25 09:25:24.3214589 |
5 | Ramesh | 2019-10-25 09:27:16.6590012 |
6 | Suresh | 2019-10-25 09:28:19.3540023 |
❮ SQL Server Functions