- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Difference 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
04-12-2002 07:37 AM
04-12-2002 07:37 AM
Is there an easy way to determine in a script the number of days between two dates?
TIA, John W.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2002 07:40 AM
04-12-2002 07:40 AM
Re: Difference between two dates?
Here he comes to save the day....pun intended :~)
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2002 07:42 AM
04-12-2002 07:42 AM
SolutionYes, this is about as easy as it gets:
#!/usr/bin/sh
DT1="12 30 1900"
DT2="12 31 2005"
DIFF=$(($(caljd.sh ${DT2}) - $(caljd.sh ${DT1})))
echo "${DT1} and ${DT2} differ by ${DIFF} days."
Note, that this method will work across huge date ranges which lie outside the range of epoch seconds.
You can also use the Date::Calc Perl module.
You can do a caljd.sh -u for full usage.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2002 07:45 AM
04-12-2002 07:45 AM
Re: Difference between two dates?
You see that little button that is labeled 'Search'. You probably should have used it first and searches for something like 'date' and 'differnece' and I suspect that you would have found a few hits.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2002 08:11 AM
04-12-2002 08:11 AM
Re: Difference between two dates?
Good luck... This is probably one of the few areas where perl would actually be better than shell/awk!
As a way of abusing this - it depends on the date format, if it's saved as 'date +%j' format it is easy:
$ date +%j
200
[100 days later]
$ date +%j
300
If it's done using the normal date format, then that makes it harder. *even* harder if it breaches a) the month and b) the year boundary.
Here is an attempt; I don't expect it to work first time :-)
----------------
#!/usr/bin/sh
# $1 = date in dd/mm/yyyy
function numdays
{
integer day=${1%%/*}
typeset month=${1%/*}
integer month=${month#*/}
integer year=${1##*/}
integer days=${day}
# now we need to work out the amount of dates in the year
while (( month > 1 ))
do
days=$(( ${days} + $(cal ${month} ${year}| awk 'BEGIN {RS="\\n"} {print NF}') ))
month=$(( ${month} - 1 ))
done
}
First=$(numdays 12/04/2002)
Second=$(numdays 10/02/2002)
print (( Second - First ))
----------------
Doing the years is left as an exercise to the reader :-)
HTH
dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2002 09:08 AM
04-12-2002 09:08 AM
Re: Difference between two dates?
This discussion might help you ...
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xea948cc5e03fd6118fff0090279cd0f9,00.html
Thanks,
Shabu