OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
Re: Subtracting date fields

From: Aftab Jahan Subedar (jahanbol-online.com)
Date: Fri Jan 30 2004 - 15:26:02 CST


try
SELECT id,(TO_DAYS(firstdate)- TO_DAYS(postdate)) AS diff FROM calendar

well you have to put the bigger date on the lhs.

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?
>
>
> Thanks,
>
> Kenneth
>

--

Aftab Jahan Subedar
CEO/Software Engineer
Subedar Technologies
Subedar Baag
Bibir Bagicha #1
North Jatrabari
Dhaka 1204
Bangladesh
http://www.SubedarTechnologies.com
http://www.DhakaStockExchangeGame.com/
http://www.CEOBangladesh.com/
http://www.NYSEGame.com
tel://+88027519050
EMail://jahanbol-online.com - Directly to my notebook

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql