1830898 Members
3096 Online
110017 Solutions
New Discussion

Re: Date Question

 
SOLVED
Go to solution
Ryan Clerk
Frequent Advisor

Date Question

Hello,

I got so many quick responses to my last question that I think I will try again. This ought to be easy be it has me completely stumped. Is there a way to determine the number of days since some date in the past. For example, how many days since today and Dec. 1, 1960?

TIA, Ryan
5 REPLIES 5
harry d brown jr
Honored Contributor
Solution

Re: Date Question

A. Clay Stephenson
Acclaimed Contributor

Re: Date Question

Actually, this is far from a trivial question but there is a fairly easy solution. Try this:

#!/usr/bin/sh
PREV_DT="12 1 1960"
DIFF=$(($(caljd.pl) - $(caljd.pl ${PREV_DT)))
echo "Diff = ${DIFF}"


Caljd.pl converts a calendar date into a Julian Day and vice versa. With no arguments, it converts today's date to a Julian Day. Caljd.pl -u gives full usage.

I've attached the caljd.pl script but you can also use the shell/awk based 'caljd.sh' script. The arguments are exactly the same. Search the Forums for 'caljd.sh' and you should find a copy. Version 2.05 is the latest.

Regards, Clay
If it ain't broke, I can fix that.
Ryan Clerk
Frequent Advisor

Re: Date Question

Thanks guys. That worked. I used the caljd.sh version because I don't know Perl.
Ryan Clerk
Frequent Advisor

Re: Date Question

Hello again,

I'm a little confused. I have been looking at this caljd.sh and I noticed that something appears to be very wrong. There is a function called "JDATE_CAL" that has 11 parameters but is is only called with 3 parameters. I have downloaded the file 3 times but each time the same parameters are missing. The funny thing is that the script seems to work fine. Is this ok?

Please respond, Ryan.
A. Clay Stephenson
Acclaimed Contributor

Re: Date Question

Not to worry, Ryan. Your version is fine. That's the standard method of declaring local variables for a function in awk. Any formal paramters in excess of the actual paramters become local variables for that function. By convention, those parameters are set apart by extra whitespace to make it more obvious. If you examine the Perl version, cajld.pl, you will note that those parameter lists match because Perl supports the concept of explicitly declared local variables.

Regards, Clay
If it ain't broke, I can fix that.