Date and Time Functions Flashcards
Which functions return the current date and time?
- GETDATE
- CURRENT_TIMESTAMP
- GETUTCDATE
- SYSDATETIME
- SYSUTCDATETIME
- SYSDATETIMEOFFSET
SQL Server 70-461 02-02b
GETDATE
Returns the current date and time in the SQL Server instance you are connected to with a data type of DATETIME.
Result Format
2012–09–30 14:10:13.813
SQL Server 70-461 02-02b
CURRENT_TIMESTAMP
Returns the current date and time in the SQL Server instance you are connected to, same as GETDATE. However, CURRENT_TIMESTAMP is standard and GETDATE is specific to SQL Server so use CURRENT_TIMESTAMP.
Result Format
2012–09–30 14:10:13.813
SQL Server 70-461 02-02b
GETUTCDATE
Returns the current date and timein the SQL Server instance you are connected to in UTC terms with a data type of DATETIME.
Result Format
2012–09–30 21:10:13.813
SQL Server 70-461 02-02b
SYSDATETIME
Returns the current date and timein the SQL Server instance you are connected to with a data type of DATETIME2(7).
Result Format
2012–09–30 14:10:13.8160822
SQL Server 70-461 02-02b
SYSUTCDATETIME
Returns the current date and timein the SQL Server instance you are connected to in UTC terms with a data type of DATETIME2(7).
Result Format
2012–09–30 21:10:13.8160822
SQL Server 70-461 02-02b
SYSDATETIMEOFFSET
Returns the current date and timein the SQL Server instance you are connected to in UTC terms with a data type of DATETIMEOFFSET(7). The time zone offset is NOT adjusted for daylight savings time.
Result Format
2012–09–30 14:10:13.8160822 –07.00
SQL Server 70-461 02-02b
How do you return the current date OR current time but not both current date AND current time?
There are no built in functions for just the current date or just the current time. To accomplish this CAST the SYSDATETIME function to DATE or TIME. For example, CAST(SYSDATETIME() AS DATE).
SQL Server 70-461 02-02b