The SQL GETDATE() is a SQL Server function which will return current SQL Server system date and time. It is similar to SQL NOW() function in mySQL or SELECT SYSDATE FROM DUAL in Oracle.
Note: In SQL Server, we can also use CURRENT_TIMESTAMP or {fn NOW()} to get the current date time, but the SQL GETDATE() is the most popular.
SQL GETDATE() Syntax
SELECT GETDATE()
SQL GETDATE() Example
Table: Coupons
CouponID | CouponName | Description | ExpireDate |
---|---|---|---|
1 | Val20 | $20 Value coupon | August 25, 2011 |
2 | Val60 | $60 Value coupon | March 10, 2011 |
3 | Off05 | 5% off | July 31, 2011 |
4 | Off15 | 15% off | June 15, 2011 |
We want to select all the coupons that are not expired:
SELECT CouponID, CouponName FROM Coupons WHERE ExpireDate > GETDATE()
Suppose that the SQL Server’s current system date is July 25, 2011, the result will look like:
CouponID | CouponName |
---|---|
1 | Val20 |
3 | Off05 |