Re: comparing dates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I found this in an old programmable calculator
library manual:

'The number of days between dates is found by
calculating the FACTOR for each date, then
finding the difference between the FACTORS.

For January and February:

FACTOR = 365 * y + d + 31 * (m - 1) +
         int((y - 1) / 4) -
         int(3 / 4 * int((y - 1) / 100 + 1))

For March through December:

FACTOR = 365 * y + d + 31 * (m - 1) -
         int(0.4 * m + 2.3) + int(y / 4) -
         int(3 / 4 * (int(y / 100) + 1) 

The day of the week is determined from the 
FACTOR for that date as follows:

dayofweek = FACTOR + int(-factor / 7) * 7

where the day is represented by a single digit 0
through 6 for Saturday through Friday'
(that is sat=0, sun=1, etc.)

I thought you might like to just have an equation
to cut and paste into your code :-)

Cheers,
Gerardo


Searching for the best free email?  Try MetaCrawler Mail, from the #1 metasearch service on the Web, http://www.metacrawler.com
-
: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Newbie]     [Audio]     [Hams]     [Kernel Newbies]     [Util Linux NG]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Device Drivers]     [Samba]     [Video 4 Linux]     [Git]     [Fedora Users]

  Powered by Linux