What is the usual way of getting current date and time from SQL Server? Obviously, the answer is GETDATE function. Do you know that there are 7 different ways of getting the same with bit differences? Here are the ways and their differences;
Function | Explanation |
GETDATE() | Returns datetime. |
GETUTCDATE() | Returns datetime in Universal Time Coordinated. |
CURRENT_TIMESTAMP | Returns datetime. This is ANSI Standard function |
SYSDATETIME() | Returns datetime2. |
SYSUTCDATETIME() | Returns datetime2 in Universal Time Coordinated. |
SYSDATETIMEOFFSET() | Returns datetimeoffset (time zone offset is included) |
ODBC Canonical functions | Not a standard way but they can be used too. There are many functions and NOW() is similar to GETDATE() which returns datetime. This has to be called as; {fn NOW()} |
- SELECT GETDATE() [GETDATE]
- SELECT GETUTCDATE() [GETUTCDATE]
- SELECT CURRENT_TIMESTAMP [CURRENT_TIMESTAMP]
- SELECT SYSDATETIME() [SYSDATETIME]
- SELECT SYSUTCDATETIME() [SYSUTCDATETIME]
- SELECT SYSDATETIMEOFFSET() [SYSDATETIMEOFFSET]
- SELECT {fn NOW()} [NOW]
No comments:
Post a Comment