- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to count the days between two dates.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 07:57 AM
03-24-2004 07:57 AM
Is there an HP-UX command that will count the number of days between two dates? I've searched the man pages and can't find anything close. This should be so simple but I can't find anything that will do this.
Thanks,
Steve
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 08:05 AM
03-24-2004 08:05 AM
Solution#!/usr/bin/sh
D1="01 01 2004"
D2="03 24 2004"
typeset -i10 DIFF=$(( ${caljd.sh ${D2}) - $(caljd.sh ${D1}) ))
echo "Diff = ${DIFF} days."
Here's caljd.sh:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 08:09 AM
03-24-2004 08:09 AM
Re: How to count the days between two dates.
typeset -i10 DIFF=$(( ${caljd.sh ${D2}) - $(caljd.sh ${D1}) ))
should be:
typeset -i10 DIFF=$(( $(caljd.sh ${D2}) - $(caljd.sh ${D1}) ))
Stupid me, I swaped '{' for '('.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 09:06 AM
03-24-2004 09:06 AM
Re: How to count the days between two dates.
I tried your solution and it gives me this error:
datediff[11]: 11 24 4713 - 11 24 4713 : Syntax error
Any ideas?
Thanks,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 09:11 AM
03-24-2004 09:11 AM
Re: How to count the days between two dates.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 09:21 AM
03-24-2004 09:21 AM
Re: How to count the days between two dates.
D1="01 01 2004"
D2="03 24 2004"
typeset -i10 DIFF=$(( $(caljd.sh ${D2}) - $(caljd.sh ${D1}) ))
echo "Diff = ${DIFF} days."
to something like this:
D1="01/01/2004"
D2="03/24/2004"
typeset -i10 DIFF=$(( $(caljd.sh ${D2}) - $(caljd.sh ${D1}) ))
echo "Diff = ${DIFF} days."
Caljd.sh expect 3 arguments for a Gregorian Date and you are supplying only 1.
You could change it to something like this:
D1="01/01/2004"
D2="03/24/2004"
typeset -i10 DIFF=$(( $(caljd.sh -S "/" -c ${D2}) - $(caljd.sh -S "/" -c ${D1}) ))
echo "Diff = ${DIFF} days."
and that should work; the -c says this is a Gregorian calendar date.
Again, invoke as caljd.sh and you will get many examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 09:34 AM
03-24-2004 09:34 AM
Re: How to count the days between two dates.
No points please, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 09:55 AM
03-24-2004 09:55 AM
Re: How to count the days between two dates.
Thanks,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 10:06 AM
03-24-2004 10:06 AM
Re: How to count the days between two dates.
You're welcome for your thanks but I am now officially out of patience. I forgot to mention that after you invoke as caljd.sh -u that is necessary to actually read the usage messages and examples.
Actually your result makes perfect sense;
the difference between 07/15/99 CE (or AD) and 03/15/04 CE is -34820 days! You probably meant 07/15/1999 but that dumb computer had no way of knowing that. Add an additional "-C" argument to each invocation of caljd.sh and that should fix you ---- and yes, this too, is explained in those silly, useless usage messages. Maybe I need to create a man page but I bet you don't bother with them either.
I feel better now,
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 10:17 AM
03-24-2004 10:17 AM
Re: How to count the days between two dates.
Sorry I didn't mean to make you mad. The last change using the -C option worked and the result was 1705 days. I'll have to get out the calendar and count the days but that looks right.
Thanks for all your help and next time I will closely read all the examples.
Thanks,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 11:16 AM
03-24-2004 11:16 AM
Re: How to count the days between two dates.
"There must be a bug in the script somewhere."
Lemme see,
On the one hand there is a script (program/application/tool, fill in the appropriate condition...) heavily recommended, heavily used, by tons of folks, tons of times.
On the other hand there is this user, who has a problem to be solved, who is trying to use to use said script/tool/application for a very first time, but that fails.
Hmmm, where might the problem be? In the tool or in its user/usage?
Nothing directed to you personnaly Steve, but I see this a lot and fail to understand how in such situation one can even consider that it would be anything other then a usage problem!
cheers!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 11:18 AM
03-24-2004 11:18 AM
Re: How to count the days between two dates.
There are not any bugs in the script.
If you wish to engage a programmer to do this for you fine. I'm available.
A. Clay has made a tremendous effort and deserves point assignment.
Please do so.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 12:07 PM
03-24-2004 12:07 PM
Re: How to count the days between two dates.
I'd really like to think you know you're one fine step away from spam in my opinion. But I'm having doubts.
I sincerely wish you'd knock that off.
This is a forum - period - not a commercial publication. And if it was, I'd urge Dan to charge you an advertising fee. At least a % of your take.
My 2 cents,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 01:17 PM
03-24-2004 01:17 PM
Re: How to count the days between two dates.
A. Clay has provided the programs, and done the shell scripting for you. His programs are not broken.
Whooooooooooooooosh
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 03:06 PM
03-24-2004 03:06 PM
Re: How to count the days between two dates.
Happy Trails and all that,
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 03:24 PM
03-24-2004 03:24 PM
Re: How to count the days between two dates.
I didn't start this, but I will finish it.
And believe me, I do have the welts.
I wonder about others....
Best Rgds,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2004 03:57 PM
03-24-2004 03:57 PM
Re: How to count the days between two dates.
you are going overboard on this.
Even is you do not get SEP's joke or do not want to get it, there is no way, that you can classify SEP's post as spam. Please, give me a break.
ACS has achieved everything there is to. He is is the top of the crop, he is olympian, so he acts according to the bible verse "Sow much and you will reap much". ;-)
As he said, lighten up,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 01:23 AM
03-25-2004 01:23 AM
Re: How to count the days between two dates.
Chuck Davis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 05:34 AM
03-25-2004 05:34 AM
Re: How to count the days between two dates.
Sorry about being late with my points assignments. I have also been properly chastised for not reading the examples. I am really amazed at what this script can do. I also searched and found the perl version of this wonderful script. Until reading about this subject, I never really thought about how hard this really is. I still don't quite know where 11 24 4713 came from when I didn't correctly use the command but I have used the script enough to know that it even handles leap years with no problems.
Thanks for everyone's input.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 09:07 AM
03-25-2004 09:07 AM
Re: How to count the days between two dates.
Anyway, here is the corrected version; caljd.sh Version 2.23; the Perl version 2.22p is fine.