On Mon, Jan 25, 2010 at 09:54:40PM -0600, Skip Evans wrote:
> Hey all,
> I have an SQL query that's stumping me.
> I have two date variables, $start and $end that are in
> mm/dd/yyyy format and two database fields, start_date and
> no_donations. The start date is mm/dd/yyyy format and
> no_donations is an integer that represents the number of
> months from start_date that donations will be made.
> So if start date is say 02/01/2010 and no_dations is 4 then
> donations will be made four times from the start date for four
> What I need to do is come up with a query that will determine
> if the start_date + no_donations falls within $start and $end.
> But I'm pretty stumped. How can I convert start_date +
> no_donations in the database to the date when the last
> donation will take place so I'll now if the donations fall
> between $start and $end?
> Any suggestions would be very help and appreciated,
If there's a way to do this in SQL itself, I don't know what it is. But
in my opinion, you need a date class which can do date comparisons.
(If you end up programming one yourself, save yourself some time and
convert all dates to Julian day numbers internally. This saves massive
amounts of computation in determining intervals and durations.
Typically, coders try to store dates in unix timestamps internally, and
then add 86400 seconds for every day to calculate intervals and such.
This is often inaccurate. Julian days are far more accurate.)
Paul M. Foster
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php