I will explain GETDATE, GETUTCDATE, SYSDATETIME and SYSUTCDATETIME functions in this article.
GETDATE Function in SQL Server(TSQL):
We can obtain current database timestamp as a datatime value using GETDATE function.
1 |
SELECT GETDATE(); |
GETUTCDATE Function in SQL Server(TSQL):
We can obtain current database timestamp as a datatime value without database timezone offset using GETUTCDATE function.
For example, the timezone of SQL Server that I run the following script is UTC+3.
As you can see below, the GETUTCDATE function worked based “UTC” instead of “UTC+3”.
1 2 |
SELECT GETDATE(); SELECT GETUTCDATE(); |
SYSDATETIME Function in SQL Server(TSQL):
We can obtain current date and time information as datetime2(7) value from the server on which SQL Server is running.
1 |
SELECT SYSDATETIME(); |
SYSUTCDATETIME Function in SQL Server(TSQL):
We can obtain current date and time information as datetime2(7) according to UTC from the server on which SQL Server is running.
1 2 |
SELECT SYSDATETIME(); SELECT SYSUTCDATETIME(); |