How can I get current Date in Sql Server 2005?

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

SELECT GETDATE()

November 10 2008 6:41 PM

DECLARE @DT DATETIME
SET @DT = GETDATE()
PRINT @DT

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 the current date.

No comments: