- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Number of 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-27-2002 01:17 PM
03-27-2002 01:17 PM
Is there a way to calculate the exact number of days between two given dates? I've been scripting using the date command but there must be an easier way to do this!!!
Any suggestions, hints, or ideas are welcome.
Thank you, Mary
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2002 01:23 PM
03-27-2002 01:23 PM
SolutionWhenever I see 'dates' I perk up. Yes, that is rather easy if you use my date hammer (now where's your date nail?), caljd.sh.
JD1=$(caljd.sh 12 25 1999)
JD2=$(caljd.sh 03 31 2003)
NUMBER_OF_DAYS=$(( ${JD2} - ${JD1} ))
caljd.sh can take a calendar date and convert it to a Julian Day (~ the number of days since 4713BCE) and when supplied with a Julian Day it spits out the calendar date. Julian Days are used by astromers to make orbital calculations much easier.
Invoke caljd.sh -u for full usage.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2002 02:31 PM
03-27-2002 02:31 PM
Re: Number of days between two dates?
CURRENT=`/usr/contrib/bin/perl -e "print time"`
NINETY='7776000'
SIXTY='5184000'
THIRTY='2592000'
NDAYS=`/usr/bin/expr $CURRENT - $NINETY`
SDAYS=`/usr/bin/expr $CURRENT - $SIXTY`
TDAYS=`/usr/bin/expr $CURRENT - $THIRTY`
You could modify these for you own purposes and come up with the same thing.
GL,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2002 04:15 PM
03-27-2002 04:15 PM
Re: Number of days between two dates?
Clay's caljd.sh is SUPER, also there was a perl script that was submitted in this forum a couple of weeks back which works pretty neat too, here is the link:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xe5d194f22a31d6118fff0090279cd0f9,00.html
It gives you the difference between two given dates in days, hours, minutes and seconds.
This script uses the Date-Calc perl module, if you don't already have it, download the tar ball from here:
http://search.cpan.org/search?dist=Date-Calc
Hope this helps !
-Shabu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2002 09:16 AM
03-28-2002 09:16 AM
Re: Number of days between two dates?
Thanks again, Mary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2002 09:29 AM
03-28-2002 09:29 AM
Re: Number of days between two dates?
$Dd = Delta_Days ($year1, $month1, $day1, $year2, $month2, $day2);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2002 11:12 AM
03-28-2002 11:12 AM
Re: Number of days between two dates?
I'm glad that you liked it. I've used the C version of that algorithm for many years. I can't claim credit for Julian Days; the concept has been around for many, many years. The algorithms I use are adapted from those published in 'Sky and Telescope'. If you researched Julian Days then you know that those in caljd.sh are not true Julian Days. The real things are actually floating-point values and can represent fractional parts of days to any desired precision. The other difference is that Julian Days actually start at noon UTC so that midnight is JD.500000.
The ones in caljd.sh are truncated (integer) Julian Days and begin at midnite local time. These tend to be more useful in the computer world. You can specify the -U option to force the current date to be evaluated as UTC though again days begin at midnite.
My favorite part about all this is that the really tricky calculations are done in just two awk functions. CAL_JDATE converts MM DD YYYY into a Julian Day and JDATE_CAL does the reverse. The really neat thing is that "30 days hath September ..." ,including leap years, is done without a single if statement.
All the other stuff in the script is command line processing, usage, and stuff to read the /etc/acct/holidays file so that you can optionally skip holidays.
Regards, Clay