curdate() returns wrong values

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
bluesman333
Forum Commoner
Posts: 52
Joined: Wed Dec 31, 2003 9:47 am

curdate() returns wrong values

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply