RSS Feed

GETDATE()

GETDATE()

Returns the current system date and time from Microsoft SQL Server standard internal format.

Example 1 of GETDATE()

Select GetDate()
[Returns current date and time]

Result of the above query is:
2010-07-07 10:13:16.810

Example 2 of GETDATE()

Below example updates the Result_date column of the Emp table for all the rows.

Update Emp
SET Result_date = GETDATE()

Example 3 of GETDATE()

Use GETDATE() with CREATE TABLE

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
[Source of example 3]