|
Posted by Gordon Burditt on 12/15/05 08:16
>Probably being a little thick here, but when you subtract one date away
>from another, how do you convert the resultant value into a number of
>days... I guess I could easily / 60 / 60 / 24... but that seems
>barbaric... Anything neater?
First off, you need to nail down what answer you want a little
more. You will not always get agreement on these:
1. How many days are there between January 1 and January 2?
My answer: NONE, those two days are next to each other, and
therefore none of them are Mondays regardless of what year it is.
2. How many days are there between January 2 and January 2 (of
the same year)? My answer: this doesn't really make sense, but
if you insist, negative one.
If, on the other hand, you're trying to figure out how many work
days there are between the morning of date X and the evening of date Y,
some people might consider the answers to the above questions as
2 and 1, respectively.
>Ps, Im also just trying to work out how to calculate the number of
>mondays and tuesdays etc between two dates... Just thought I'd run this
>theory past you if I may to gain more confidence.
>
>I figure getting the date difference, and knowing that the starting date
>falls on a Thursday holds the key... working out the days between these
>two dates should be easy enough to divide by 7 to get the whole number
>and remainder (is that a mod?)... we can just say there's x number of
>Wednesdays, x number of Thursdays etc, and then just loop through the
>remainder which is a small number so not much of system load?
I had occasion to do some calculations to determine the next <day
of week> or first <day of week> in <month> after the given date.
Your calculations will likely involve a lot of % 7 or / 7 operations,
occasionally with adding 7 to avoid negative numbers being fed to
%. You can probably avoid a loop.
Gordon L. Burditt
Navigation:
[Reply to this message]
|