SQL > SQL Date Functions > Getdate Function

The GETDATE function is used to retrieve the current database system time in SQL Server. A common use of GETDATE is to get today's date.

Syntax

The syntax for the GETDATE function is,

GETDATE( )

GETDATE does not require any argument.

Example

The SQL statement,

SELECT GETDATE( );

produces the following result when run on March 15, 2000, at 00:05:02.123 AM.

'2000-03-15 00:05:02.123'

GETDATE function is most useful when we need to record the time a particular transaction happens. In SQL Server, we simply insert the value of the GETDATE( ) function into the table to achieve this. We can also set the default value of a column to be GETDATE( ) to achieve the same purpose.

The Oracle and MySQL equivalent of GETDATE is SYSDATE.

List of SQL Date Functions

Function NameDescription
DATEADDAdds an interval to a date value in SQL Server.
DATEDIFFCalculates the difference between two dates in MySQL and SQL Server.
DATEPARTExtracts a specific part of a date/time value in SQL Server.
GETDATERetrieves database time in SQL Server.
SYSDATERetrieves database time in Oracle and MySQL.

Next: SQL SYSDATE




Copyright © 2017   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact