List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:August 2 1999 7:16pm
Subject:Re: How to do math with dates
View as plain text  
At 2:47 PM -0400 8/2/99, Silicon Ghost wrote:
>I am trying to do the following SELECT statement, but I need the answer
>returned to be a single digit number.  If I do this in an Excel formula for
>example, the answer for the statement below is 2, which is what I want.
>
>(the CURRENT_DATE is 1999-08-02)
>
>mysql> SELECT ROUND(((CURRENT_DATE-"1999-07-19")/7),0);
>+------------------------------------------+
>| ROUND(((CURRENT_DATE-"1999-07-19")/7),0) |
>+------------------------------------------+
>|                                  2855543 |
>+------------------------------------------+
>
>Also, I tried entering the exact same thing as above, but I manually entered
>today's date.  This gave me 0 as an answer.  I don't quite understand that
>either.  See my example below:
>
>mysql> SELECT ROUND((("1999-08-02"-"1999-07-19")/7),0);
>+------------------------------------------+
>| ROUND((("1999-08-02"-"1999-07-19")/7),0) |
>+------------------------------------------+
>|                                        0 |
>+------------------------------------------+
>
>Any suggestions?


You might find the TO_DAYS() function useful for converting dates to days.
Then you can do your math.

-- 
Paul DuBois, paul@stripped
Thread
How to do math with datesSilicon Ghost2 Aug
  • Re: How to do math with datesPaul DuBois2 Aug
  • Re: How to do math with datesMartin Ramsch3 Aug
  • Re: How to do math with datesChristian Mack3 Aug