Page 1 of 1

curdate() returns wrong values

Posted: Mon Aug 08, 2005 2:40 pm
by bluesman333
I'm tring to calculate the aging value of an invoice. Here is the SQL statement:

SELECT invoice_number, company_name, curdate( ) , invoice_date,
curdate( ) - invoice_date AS aging
FROM invoices

Here is one of the lines that is returned:
56554 Company A 2005-08-08 2005-07-28 80

The aging value is 80 but should be 11.

Posted: Mon Aug 08, 2005 3:10 pm
by feyd
if you do the math.. it acutally is 80. Not date math, as in convert the two dates to numeric (perform them as math operations.)

if you have MySQL 4.1.1+ you can use DATE_DIFF().. otherwise, you can convert them to unix timstamps: UNIX_TIMESTAMP() then do the actual math.