- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Working with date using shell scripts
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
Discussions
Discussions
Discussions
Forums
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
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
тАО07-04-2006 10:03 PM
тАО07-04-2006 10:03 PM
This is about date calculations. The question is,
Suppose today is 25 Feb 2004. How do I correctly find out the date after 10 days? (Consider month change, leap year etc.)
Is there any function which I could use straigt away?
I do give points to responses.
Thanks in advance!
Anoop
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2006 10:12 PM
тАО07-04-2006 10:12 PM
Re: Working with date using shell scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2006 10:13 PM
тАО07-04-2006 10:13 PM
Re: Working with date using shell scripts
get a copy of the excellent caljd package by A. Clay Stephenson.
One version at:
http://mirrors.develooper.com/hpux/
right at the bottom of the page.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-04-2006 10:14 PM
тАО07-04-2006 10:14 PM
Re: Working with date using shell scripts
You can use A.Clay's script (Caljd)
http://mirrors.develooper.com/hpux/caljd-2.25.sh
http://mirrors.develooper.com/hpux/caljd-2.2.pl
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2006 02:20 AM
тАО07-05-2006 02:20 AM
SolutionTODAYPLUS10=$(caljd.sh -S "/" $(caljd.sh -n 10))
echo "10 days from now is ${TODAYPLUS10}"
And, yes, it works across year boundaries, leap years. It can also calculate n days from a given date in either direction and can even optionally skip days in the week so that "10 days from now unless that is a weekend" also works. In that case, the next non-excluded day is output.
Invoke as caljd.sh -u for usage and many examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2006 02:29 AM
тАО07-05-2006 02:29 AM
Re: Working with date using shell scripts
No disrespect to A.Clay's script, but you could also download gnu date and use it thusly:
$ date --date="10 days"
Sat Jul 15 09:24:42 CDT 2006
$ date
Wed Jul 5 09:24:43 CDT 2006
$ date --date="3 days ago"
Sun Jul 2 09:29:02 CDT 2006
Other, more standard formatting strings can be used as well...
gnu date, and other gnu utilies can be found at: http://hpux.cs.utah.edu/hppd/hpux/Gnu/sh_utils-2.0/
HTH;
Doug
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2006 05:42 AM
тАО07-05-2006 05:42 AM
Re: Working with date using shell scripts
i remember that, in a particular year(around 1800 i think), they suddenly changed to a new year format.. so some 10 days missed in that particular month..
is ur script considers that also..?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2006 07:17 AM
тАО07-05-2006 07:17 AM
Re: Working with date using shell scripts
One of the contributory reasons for Napoleon's victory at Austerlitz in 1805 was that the Russians were still using the Julian calendar while the Austrians and English were using the Gregorian calendar so that when the allies agreed to converge their forces they agreed on a date that was nevertheless a different day.
The "short" September in 1752 also caused riots (particularly in Ireland) when the landlords showed up to collect the rent. The landlords were justly saying the a new month was here and the tenets were justly saying that they were cheated out of two weeks --- and both were right and wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2006 04:47 PM
тАО07-05-2006 04:47 PM
Re: Working with date using shell scripts
Thanks for all who responded. A.Clay's solution helped me through, but I had problems to get the date in the format "DD-MMM-YY" Any ways, I wrote some lines on my own to accomplish that.
Clay, The script is good, but I have one suggestion to standardize it like many other HPUX commands. The script returns the Julian day if executed with out any option, but I expected it to return the usage. To know how to use it, I had to give lots of wrong arguments :) until today when I saw that it had the -u option. Thats just a suggestion.
Great script; hats off to you.
Have assigned points as usual.
Cheers!
Anoop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2006 05:40 PM
тАО07-05-2006 05:40 PM
Re: Working with date using shell scripts
I've ported A. Clay's script to Linux (1 line fix, change the shell). I had to do a fair amount of testing on it because its a production script on all my Linux/HP-UX server.
I think there is a way to use it to exactly get your date format. Otherwise maybe he'll upgrade it.
What do you mean by standardize like other HP-UX commands? Its not part of the OS, its an add in. Maybe A. Clay should sell it to HP as part of the OS?
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
тАО07-05-2006 05:55 PM
тАО07-05-2006 05:55 PM
Re: Working with date using shell scripts
I will reframe it this way. "Standardize like other Unix commands"
Unix commands which need an argument to function normally, output the usage syntax, when ever no argument is passed with the command. A usual behavour.
I was suggesting to have this feature here too. I dont insist.
Thanks!
Anoop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2006 08:45 PM
тАО07-05-2006 08:45 PM
Re: Working with date using shell scripts
http://fresh.t-systems-sfr.com/unix/src/privat2/mktime-2.3.tar.gz/
To obtain your date:
mktime -F %y%m%d -d+10
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-06-2006 04:35 AM
тАО07-06-2006 04:35 AM
Re: Working with date using shell scripts
Now there was a subtle bug when combining outputting month names with a non-whitespace separator but this is fixed in the version, 2.27, attached here.
To get 10 days from today in DD-MMM-YYYY format the solution is:
TODAYPLUS10=$(caljd.sh -e -S "-" -o $(caljd.sh -n 10))
echo "10 days from now is ${TODAYPLUS10}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-06-2006 05:50 PM
тАО07-06-2006 05:50 PM
Re: Working with date using shell scripts
I think you are right. Thank you for the script and the explanation.
Anoop