GETDATE function is used to get current system date in the sql server standard internal format for datetime values.It can be used in select list of select statement or where clause of a query.
It also used in report to print current date and time and tracking activity.
Syntax of GETDATE Function :
GETDATE()
Return type of this function is datetime.
Examples of GETDATE Function :
Examples 1 : Use of GETDATE function in SELECT clause
SELECT GETDATE()
Output
2002-08-02 15:05:20.277
Above example display a current system date in sql sever in the format 'YYYY-MM-DD hh:mi:ss.ms'
Example 2 : Use of GETDATE function in where clause
SELECT ShipName, OrderDate
FROM Orders
WHERE DAY(OrderDate) = DAY(GETDATE())
Output
ShipName OrderDate
Rattlesnake Canyon Grocery 1996-08-02 00:00:00.000
Vins et alcools Chevalier 1996-09-02 00:00:00.000
Tortuga Restaurante 1996-10-02 00:00:00.000
Above example displays orders having same day as system date.