Stuart Brian Stuart Brian - 12 days ago 5
SQL Question

Sql query to check if the expiry date is passed

I am trying to select expired contract from my data base but is not working very fine please i deed help

It was saved in data base this way

pid | name | booking_date | expiry_date
------|--------|--------------|-----------------
1 | home | 2016-01-17 | 2016-11-11
2 | home+ | 2016-07-17 | 2016-10-03
3 | home++ | 2016-02-17 | 2017-13-10


SELECT * FROM hostel_client
WHERE expiry_date >= NOW() - expiry_date
ORDER BY expiry_date ASC
LIMIT 0,30


I need to output only expired contract
PID
1 and 2

Answer

Try less than < instead of greater than >

SELECT * FROM hostel_client 
WHERE expiry_date < NOW()
ORDER BY expiry_date ASC 
LIMIT 0,30