You can't subtract dates like that. You need to use the built in date/time
functions. See the following:

http://www.mysql.com/doc/D/a/Date_calculations.html
http://www.mysql.com/doc/D/a/Date_and_time_functions.html

Your query would be something like this:

SELECT TO_DAYS(completion_date) - TO_DAYS(order_date) AS days_elapsed ...

--jeff

----- Original Message -----
From: "Brandon McCombs" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, July 13, 2002 8:34 PM
Subject: date subtraction error


> Hi,
>
> Maybe I'm missing something but I tried solution someone posted for
> someone else's problem concerning finding out # of days between 2 dates.
>
> I have 2 sets of dates I'm working with in my sample DB.
>
> order_date  completion_date
> 2002-07-03  2002-07-09
> and
> 2002-06-27  2002-07-08
>
> Now the query I'm using is the following:
> select (completion_date-order_date) as days_elapsed from received where
> completion_date != 0;
>
> I get the following as a result:
> 6
> 81
>
> Obviously there isn't 81 days between June 27th and July 8th. Can anyone
> tell me why mysql does the calculation this way and if there is a more
> correct way of doing the subtraction of the dates?
>
> Thanks
> Brandon
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
<[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to