Using GETDATE

Accessing and Changing Relational Data

Accessing and Changing Relational Data

Using GETDATE

The GETDATE function produces the current date and time in Microsoft® SQL Server™ internal format for datetime values. GETDATE takes the null parameter ( ).

This example finds the current system date and time:

SELECT GETDATE()

Here is the result set:

-------------------------
July 29 1995   2:50    PM

(1 row(s) affected)

You can use GETDATE in designing a report to have the current date and time printed every time the report is produced. GETDATE is also useful for functions such as logging the time a transaction occurred on an account.

You can use GETDATE anywhere to return the current system date. For example, you can use GETDATE as a default value for data entry, with a local variable, or comparing an order date to today's date.

See Also

Date and Time Functions