SQL Get Current Date
Databases allow you to compare a column or result set against today's current date.PostgreSQL, MySQL, Oracle
SQL Server
select
*
from
rent_payments
where
payment_date < current_date;
Assume that we run this query on March 5th, 2018 (3/5/2018
).
rent_payments
table
id | payment_date | dollar_amount |
---|---|---|
1 | 3/1/2018 | 2000 |
2 | 3/2/2018 | 1500 |
3 | 3/1/2018 | 1800 |
4 | 3/3/2018 | 1900 |
5 | 4/2/2018 | 2000 |
6 | 4/2/2018 | 1900 |
Query results
id | payment_date | dollar_amount |
---|---|---|
1 | 3/1/2018 | 2000 |
2 | 3/2/2018 | 1500 |
3 | 3/1/2018 | 1800 |
4 | 3/3/2018 | 1900 |