SQL Server GETDATE() Function
The GETDATE()
function in SQL Server retrieves the current date and time from the database server's system clock. This function is very useful for adding timestamps to your data or for performing time-based calculations within your SQL queries.
GETDATE(): Definition and Usage
GETDATE()
is commonly used to record when a database event occurs, to track changes in data, or to generate time-sensitive reports. The returned datetime value is formatted as 'YYYY-MM-DD hh:mm:ss.mmm'. Keep in mind that the time returned is the time on the *server* where the database is running, which might differ from the time on your client machine.
Syntax
Syntax
GETDATE()
Return Type
GETDATE()
returns a datetime
value.
Example
Retrieving the Current Date and Time
This query demonstrates obtaining the current datetime from the SQL Server instance.
Syntax
SELECT GETDATE();
Output
2024-11-16 11:38:42.123 (Example output - the actual time will vary)
Related Function
For getting the current timestamp in UTC (Coordinated Universal Time), see the GETUTCDATE()
function.