Here is an algorithm.

old (HH)
<本文发表于: 相约加拿大:枫下论坛 www.rolia.net/f >
Here is a C function showing an algorithm to convert Gregorian calendar date to Julian day number Jday.

unsigned long
Jday(unsigned month, unsigned day, unsigned year)
{
/*
* The following two autos are just for clearity
*/
unsigned long century;
unsigned long years;

/*
* The code for argument validation is ignored here.
*/

if (month > 2)
month -= 3;
else {
month += 9;
year--;
}

century = (unsigned long) year / 100;
years = (unsigned long) year % 100;

return ((146097UL * century) >> 2) + ((1461UL * years) >> 2)
+ (unsigned long) ((153 * month + 2) / 5 + day) + 1721119UL;
}

Porting this function to Shell Script we can get days between almost any two given dates. For exampple:
Jday(6, 4, 2002) - Jday(6, 4, 1989)

It is said that the algorithm is from Communications of the ACM, Volume 6, No. 8, (Aug. 1963), p. 444. I never read it.

I am not sure the exact range of the valid date. Because Gregorian calendar started on September 14, 1752, I think the range of valid date in this algorithm should be at least from September 14, 1752 to the date which is limited by the maximum value of the number used in the Shell Script.
<本文发表于: 相约加拿大:枫下论坛 www.rolia.net/f >

(#132958@0)
2001-7-15 -05:00


回到话题: I came across this post in chinasmile. Nobody has answered his question yet. I couldn't figure out a way to do it with shell scripts, although

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论

URL:   
http://www.rolia.net/zh/post.php?f=0&p=132958