Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I use curdate() function

Status
Not open for further replies.

lhugh

MIS
May 21, 2000
115
CA
Why curdate() does not work for my query?

I would like to to find all softwares that are going to expire within the next 60 days.

The query should have returned 3 rows, not 2.


Here is the list of all records in my table:

mysql> select title, expiry_date from license;
+--------------------------+-------------+
| title | expiry_date |
+--------------------------+-------------+
| Microsoft Office | 2004-06-10 |
| Microsoft Visio | 2004-03-31 |
| RedHat Linux | 2004-04-10 |
| Oracle Enterprise Server | 2004-07-22 |
| Photoshop | 2004-05-05 |
+--------------------------+-------------+
5 rows in set (0.00 sec)


===========================================

And here is the query to find expiring / expired software

mysql> select title,expiry_date from license
-> where (expiry_date - curdate() ) <= 60;
+-----------------+-------------+
| title | expiry_date |
+-----------------+-------------+
| Microsoft Visio | 2004-03-31 |
| RedHat Linux | 2004-04-10 |
+-----------------+-------------+
2 rows in set (0.00 sec)
 
Use:[tt]
SELECT title,expiry_date
FROM license WHERE expiry_date <= DATE_ADD(curdate(),INTERVAL 60 DAY)[/tt]


When you use the expression date1 - date2, the dates are converted into numbers (e.g. 2004-04-01 becomes 20040401) and then subtracted, which is totally wrong.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top