1834800 Members
2845 Online
110070 Solutions
New Discussion

Re: Date problem

 
SOLVED
Go to solution
John Chaff
Advisor

Date problem

Hello experts,

Is there a way in HP UNIX to find the difference in days between two dates?

TIA,
John
7 REPLIES 7
Rick Garland
Honored Contributor

Re: Date problem

There are many posts concerning a 'date_calj.sh' script out there. Available for download from these forums.

I believe that is the name of the script. Will do all kinds of date calculations and math.


A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Date problem

A date problem, hmmm, I wonder what tool to use?


DT1="01 31 2005"
DT2="04 13 2005"

typeset -i DIFF=$(( $(caljd.sh ${DT2} - $(caljd.sh ${DT1}) ))
echo "Difference between ${DT2} and ${DT1} = ${DIFF} days."

If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Date problem

I should add invoke as caljd.sh -u for full usage and examples.
If it ain't broke, I can fix that.
John Chaff
Advisor

Re: Date problem

Hi Clay,

I ran your example and it prints an error:

date.sh[5] 11 24 -4713 - 11 24 -4713 : syntax error

Did you mistype your example?

Thanks,
John

A. Clay Stephenson
Acclaimed Contributor

Re: Date problem

John, John, John, ...

No but my psychic, Miss Cleo, tells me that you did. She said that my example was changed
from:

DT1="01 31 2005"
DT2="04 13 2005"

typeset -i DIFF=$(( $(caljd.sh ${DT2} - $(caljd.sh ${DT1}) ))
echo "Difference between ${DT2} and ${DT1} = ${DIFF} days."

to:

DT1="01/31/2005"
DT2="04/13/2005"

typeset -i DIFF=$(( $(caljd.sh ${DT2} - $(caljd.sh ${DT1}) ))
echo "Difference between ${DT2} and ${DT1} = ${DIFF} days."

Miss Cleo ran out of Windex so her crystal ball was a bit fuzzy; she couldn't quite see dates you entered but she could see the slashes.

If you are going to use dates like 01/31/2005 then you must add the -c and -S "/" arguments. All of this was in the usage messages if you had bothered to do a caljd.sh -u.
If it ain't broke, I can fix that.
John Chaff
Advisor

Re: Date problem

Thank you Clay. That was the problem. You are right. I should have read the instructions. Sorry.

Thanks again,
John
John Chaff
Advisor

Re: Date problem

Closed.