intro
Let's learn everything you need to know about the SQL Server GETDATE function to get the system's current date and time.
Most technologies come with a function to get the current date and time. That is part of the date utilities provided by the standard API of most programming languages. It is no surprise that SQL Server also has such a built-in feature. This is what the SQL Server GETDATE
function is all about!
In this article, you will explore the GETDATE
SQL Server function and learn how and when to use it.
Let's dive in!
What Is GETDATE in SQL Server?
GETDATE
is an SQL Server function that returns the current timestamp in a timezone specified by default or specified by the user. Specifically, it provides the current database date and time without time zone offset. That reflects the date and time from the operating system of the computer the SQL Server instance runs on.
Note: Since GETDATE
is a nondeterministic function, views and expressions referencing this function in a column cannot be indexed.
SQL Server GETDATE Function: Syntax and First Example
Here is the syntax of the SQL Server GETDATE
function:
1
GETDATE()
As you can see, it does not accept any argument.
You can use it to retrieve the current date and time of the database server as below:
1
SELECT GETDATE();
The result will be something like this:
1
2024-07-30 15:48:33
Verify that in a fully-featured SQL Server database client like DbVisualizer:

Now, you may be wondering about the resulting format of the SQL Server GETDATE
function. Thanks to DbVisualizer, you can simply click on the resulting data cell to discover it. You can find out more details about this feature in the documentation.
As indicated in the bottom left bar, GETDATE
returns a timestamp in the "yyyy-MM-dd HH:mm"
format.
The return data type of GETDATE
is DATETIME
, which is used in SQL Server to represent timestamps. If you are not familiar with the DATETIME
data type, take a look at our guide on SQL date data types.
Use Cases of the GETDATE SQL Server Function
Explore the three most common use cases of GETDATE
in SQL Server.
1 — Using It as a Timestamp for Data Insertion
When inserting new records into a table, GETDATE
can be used to automatically record the timestamp of when the record was added:
1
INSERT INTO Orders (ProductId, CustomerId, Quantity, OrderedAt)
2
VALUES (14, 1, 2, GETDATE());
Similarly, you can specify as a default value when using a CREATE TABLE
query:
1
CREATE TABLE Orders (
2
OrderID INT PRIMARY KEY,
3
ProductID INT NOT NULL,
4
CustomerID INT NOT NULL,
5
Quantity INT NOT NULL,
6
OrderedAt DATETIME DEFAULT GETDATE()
7
);
2 — Filtering Records by Current Date
The SQL Server GETDATE
function makes it easier to filter records based on the current date and time, as in this example:
1
SELECT *
2
FROM Orders
3
WHERE OrderAt < DATEADD(DAY, -1, GETDATE());
This will return all orders placed before yesterday:

Learn more about DATEADD
in our guide on SQL add to date operations.
3 — Calculating Age or Time Difference
GETDATE
can also be employed to calculate the difference between the current date and another date, such as when determining the age of a person:
1
SELECT Id, Name, DATEDIFF(YEAR, DateOfBirth, GETDATE()) AS Age
2
FROM Employees;
This relies on the SQL Server DATEDIFF
function.
Extra: How To Get Time From GETDATE in SQL Server
The GETDATE
SQL Server function returns both data and time, but what if you are interested only in the time component? Since SQL Server does not provide a specific function to get the current time, you can extract that information from GETDATE
as explained in the following approaches!
Get the TIME Component
1
SELECT CAST(GETDATE() as TIME);
The result will be something like in HH:mm:ss.nnnnnnn
format:
1
15:48:33.9900000
Discover more in our guide on how to extract date and time in MS SQL Server.
Get the Time Component as a String
To get the time component from GETDATE
as a string, format the resulting DATETIME
value with the FORMAT
function:
1
SELECT FORMAT(GETDATE(), 'HH:mm:ss');
The result will be a string containing:
1
15:48:33
Get Hours, Minutes, and Seconds
If you need only the hour, minute, or second, you can extract this information with DATEPART
as below:
1
SELECT
2
DATEPART(HOUR, GETDATE()) AS CurrentHour,
3
DATEPART(MINUTE, GETDATE()) AS CurrentMinute,
4
DATEPART(SECOND, GETDATE()) AS CurrentSecond;
The result will be:

Similarly, you can use this approach to get the current year, month, and date from GETDATE
.
Note that DbVisualizer makes it easier to write such queries thanks to its SQL editor autocomplete capabilities:

Conclusion
In this guide, you saw what the GETDATE
SQL Server function is and how it works. You now know that GETDATE
in SQL Server returns the current date and time of the machine the database server is installed on. Thanks to the use cases presented here, you also learned when to use it.
Dealing with date functions and formats becomes easier with a powerful client tool like DbVisualizer. This comprehensive database client supports several DBMS technologies, has advanced query optimization capabilities, and can generate ERD-type schemas with a single click. Try DbVisualizer for free!
FAQ
Is GETDATE part of the ANSI SQL standard?
No, GETDATE
is a function that is specifically part of the SQL Server dialect. That means you may not find the SQL Server GETDATE
function in other databases. Even if it is available, it might not have the same implementation and could produce different results.
What is the difference between GETDATE and CURRENT_TIMESTAMP in SQL Server?
Both GETDATE
and CURRENT_TIMESTAMP
return the current database system timestamp as a DATETIME
value, without the database time zone offset. The main difference between the two is that GETDATE
must be called as a function while CURRENT_TIMESTAMP
is a constant. In detail, CURRENT_TIMESTAMP
is the ANSI SQL equivalent to GETDATE
.
SQL Server GETDATE without time: Is it possible?
While the GETDATE
SQL Server function always returns a DATETIME
value with both a date and time component, you can use the CAST
function to extract only the date:
1
SELECT CAST(GETDATE() AS DATE) AS CurrentDate;
The result will be something like:
1
2024-07-30
What is the difference between the SQL Server GETDATE and GETUTCDATE functions?
The difference between GETUTCDATE
and GETDATE
in SQL Server is the time zone context they return. GETDATE
returns the current date and time based on the server's local time zone, while GETUTCDATE
returns the current date and time in UTC.
What is the difference between SYSDATETIME and GETDATE in SQL Server?
The difference between SYSDATETIME
and GETDATE
in SQL Server is the precision of their results. SYSDATETIME
returns the current date and time in the DATETIME2
data type, with precision in nanoseconds, while GETDATE
returns the current date and time using the DATETIME
data type, with precision in milliseconds.