On Sat, 2004-01-31 at 14:57, Kenneth Letendre wrote: > 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? >
Try running your query as follows: SELECT id, DATEDIFF(firstdate, postdate) AS diff FROM calendar; This will return the number of days from the first to the second day. See: http://www.mysql.com/doc/en/Date_and_time_functions.html#IDX1373 Thanks, Ryan Yagatich > > Thanks, > > Kenneth -- ,_____________________________________________________, \ Ryan Yagatich [EMAIL PROTECTED] \ / Pantek Incorporated (877) LINUX-FIX / \ http://www.pantek.com/security (440) 519-1802 \ / Are your networks secure? Are you certain? / \___A9062F5C3EAE81D54A28A8C1289943D9EE43015BD8BC03F1___\ -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]