[UPHPU] mysql date calculation bug
Orson Jones
orson.uphpu at bookstore.usu.edu
Wed Oct 17 15:37:52 MDT 2007
> none whatsoever. i had a couple of discussions about this as well [that
> would, likely, be my preferred method. it more closely matches my m.o.]
> but the talks resulted in php having the same issues as mysql. :( php
> handles this particular date scenario in the same manner as the dbms.
If I were doing it by hand (with a paper calendar with pretty pictures on it) I
would do it the same way.
Six months from Feb 28 is Aug 28.
Six months from Mar 1 is Sept 1.
The fact that your contracts use months guaranties that you will have this
problem, no matter where you do the calculation. (db, php, back of napkin)
(Easy answer: get a lawyer to bend the word month for you.)
To improve performance, I might calculate the date(s) in php, then supply the
date(s) to the db.
**Alternate Idea #1**
Now, another approach would be to pre-calculate (using whatever means necessary)
the desired 6 month target for each start date and store that result in a table.
Then query the database for the dates that you are supposed to do, then query
for people to email and Wamo! You have your list with no crazy calculations
necessary.
**Alternate Idea #2**
Use google to calculate the number of days for you.
http://www.google.com/search?q=6+months+-+45+days
(Click on the link. It is very official looking.)
Google gives: (6 months) - (45 days) = 137.621099 days
Then just round that to 138 and query for dates 138 days ago.
Orson
More information about the UPHPU
mailing list