1838219 Members
5573 Online
110125 Solutions
New Discussion

Please Help!!!

 
SOLVED
Go to solution
Robert Comber
Advisor

Please Help!!!

Help!!

I 've been beating my head against a wall for days trying to find a neat way to count the number of days between dates like
01/15/2001 and 12/15/2002. Does anybody have a program or a script that will do this?

Thanks, Bob
7 REPLIES 7
Pete Randall
Outstanding Contributor

Re: Please Help!!!

Bob,

You have two choices - you can search for "date hammer", or you can wait for Clay to notice this post and respond.

Pete

Pete
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Please Help!!!

Okay Bob, this is easy.

I. Take two Advil.

2. Download the attached script, caljd.sh, and put in in your PATH.

C. DT1=01/15/2001
DT2=12/15/2002

DAYS=$(($(caljd.sh -S "/" -c ${DT2}) - $(caljd.sh -S "/" -c ${DT1})))
echo "Days difference = ${DAYS".

Now wasn't that easy? Invoke as caljd.sh -u for full usage.


Regards, Clay
If it ain't broke, I can fix that.
Ken Hubnik_2
Honored Contributor

Re: Please Help!!!

Do a man on difftime and see if you can use it.
A. Clay Stephenson
Acclaimed Contributor

Re: Please Help!!!

Ooops, that should have been:

echo "Days difference = ${DAYS}".

You can also search for 'caljd.pl' if you want a Perl version of the script. The arguments are exactly the same. By the way, make sure that you use 4-digit years because caljd.sh (or .pl) will take you at your word and compute for 1st century AD dates.

If it ain't broke, I can fix that.
Pete Randall
Outstanding Contributor

Re: Please Help!!!

And, Bob - don't give me any points for that answer. Give them to Clay, instead. He needs them - but more importantly, he deserves them.

;^)
Pete

Pete
Robert Comber
Advisor

Re: Please Help!!!

Wow Guys!! This is great and my headache is gone!

I just did a search on "caljd" and found tons of cool ideas. It took me a little while to understand that $(cajld.sh) was the same as `calsh.sh` and I had no idea what $(( )) did but it worked perfectly the very first time.

I can't thank you guys enough.

Bob
Leslie Chaim
Regular Advisor

Re: Please Help!!!

If you have perl and the Date::Manip module:

perl -MDate::Manip -le 'print Delta_Format(DateCalc("01/15/2001", "12/15/2002", \$err, 3), 0, "%dv")'
If life serves you lemons, make lemonade