Jaa


GETDATE (Transact-SQL)

Returns the current system date and time in the SQL Server 2005 standard internal format for datetime values.

Topic link iconTransact-SQL Syntax Conventions

Syntax

GETDATE ( )

Return Types

datetime

Remarks

GETDATE is a nondeterministic function. Views and expressions that reference this column cannot be indexed.

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 that the report is produced. GETDATE is also useful for tracking activity, such as logging the time a transaction occurred on an account.

Examples

A. Using GET DATE to return the current date and time

The following 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)

B. Using GETDATE with CREATE TABLE

The following example creates the employees table and uses GETDATE for a default value for the emp_hire_date.

USE AdventureWorks;
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

See Also

Reference

Date and Time Functions (Transact-SQL)
CURRENT_TIMESTAMP (Transact-SQL)
GETUTCDATE (Transact-SQL)

Help and Information

Getting SQL Server 2005 Assistance