Matt, Good point, although he didn't specify what version he was using so I assumed a newer one. Perhaps a disclaimer should have been included? Anyways, Kenneth, if you're using an older version try this:
SELECT id, TO_DAYS(firstdate) - TO_DAYS(postdate) AS diff FROM calendar Dan -----Original Message----- From: Matt W [mailto:[EMAIL PROTECTED] Sent: Thursday, January 01, 2004 4:42 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: Subtracting date fields Dan, DATEDIFF() only works in MySQL 4.1.1+. RTFM! ;-) Matt ----- Original Message ----- From: <[EMAIL PROTECTED]> Sent: Wednesday, December 31, 2003 2:10 PM Subject: RE: Subtracting date fields > Kenneth, > > try > > SELECT id, DATEDIFF(firstdate, postdate) AS diff FROM > calendar > > RTFM! > > hope that helps, dan > > -----Original Message----- > From: Kenneth Letendre > Sent: Saturday, January 31, 2004 1:51 PM > Subject: Subtracting date fields > > > Hello, > > I'm trying to get the difference (in days) between > dates stored in two > date fields. > My query: > > SELECT id,(firstdate- postdate) AS diff FROM calendar > > This works fine if the two dates are in the same > month, but not > otherwise. MySQL appears to be treating the two dates > as base-10 integers > rather than dates. E.g.: > > 2004-01-07 (20,040,107) - 2003-12-31 (20,031,231) = > 8876 > > How do I get MySQL to treat these date fields as > date fields in this case? > > > Thanks, > > Kenneth -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]