Returns the current system date and time in the Microsoft® SQL Server™ standard internal format for datetime values.
GETDATE()
datetime
Date functions can be used in the SELECT statement select list or in the WHERE clause of a query.
In designing a report, GETDATE can be used to print the current date and time every time the report is produced. GETDATE is also useful for tracking activity, such as logging the time a transaction occurred on an account.
This example finds the current system date and time.
SELECT GETDATE()
GO
Here is the result set:
-------------------------
July 29 1998 2:50 PM
(1 row(s) affected)
This example creates the employees table and uses GETDATE for a default value for the employee hire date.
USE pubs
GO
CREATE TABLE employees
(
emp_id char(11) NOT NULL,
emp_lname varchar(40) NOT NULL,
emp_fname varchar(20) NOT NULL,
emp_hire_date datetime DEFAULT GETDATE(),
emp_mgr varchar(30)
)
GO