- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Date question
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
06-13-2002 03:12 PM
06-13-2002 03:12 PM
I have a problem that ought to be very simple. I can't find a utility that will let me calculate the date one week from some date. For example, if I have a date of 01-06-2001, how can I get 08-06-2001? This example is easy but it becomes more difficult at the end of a month or the end of a year. My dates need to be dd-mm-yyyy. I've already read the date man pages so please don't ask me to do that.
Thanks in advance for any help.
Kris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 03:17 PM
06-13-2002 03:17 PM
Re: Date question
I'm not taking credit for this, but Sir A. Clay Stephenson's date hammer will get most people's vote in here. Here is one link which has it. My suggestion is to do a search from over here <-- on 'caljd.sh' on you'll find many examples as well!
http://forums.itrc.hp.com/cm/QuestionAnswer/1,11866,0x06ed660142b2d5118ff10090279cd0f9,00.html
Cheers
~Michael~
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 03:28 PM
06-13-2002 03:28 PM
SolutionI ought to tell you to use that little search button but since you are a new Forums member, I'll make nice and I will admit that your request is a little tricky. It's time to introduce you to my date hammer (now where's your date nail), 'caljd.sh'. This guy takes calendar dates and turns them into Julian Days (~ number of days since 4713BCE) and also does the reverse.
This should fix you:
-------------------------------------------
#!/usr/bin/sh
while [ $# -ge 1 ]
do
DT=${1}
DT7=$(caljd.sh -e -S "-" $(caljd.sh -n 7 -e $(echo "${DT}" | awk 'BEGIN {FS="-"} print $1,$2,$3}')))
echo "${DT7}"
shift
done
exit 0
----------------------------------------
Note the "\" line continuation characters. If I haven't made a stupid typo that should work,
processing each argument supplied to this script. You will need to use the attached script 'caljd.sh' and make sure that it is in your PATH. If you are completely confused (and you should be at this point), after you install caljd.sh, execute caljd.sh -u and it will give full usage. Let me know if I messed up all this typing because there were enough ('s and $'s to confuse anybody. In case you are wondering where the one week came in, that's the -n 7, the -e says dd/mm/yyyy format and the -S "-" says use "-" to separate the fields.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 03:33 PM
06-13-2002 03:33 PM
Re: Date question
Forget my "Note the '\' line continuation character" comments. They were there when I posted but it looks like they were magically removed when I submitted. I should also tell you that there is a Perl version, caljd.pl that you should be able to retrieve with a search. The arguments are exactly the same, you simply substitute caljd.pl for caljd.sh. It's your choice.
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2002 03:43 PM
06-13-2002 03:43 PM
Re: Date question
I'm an idiot. I missed a '{' just before the 'print' statement in the awk part of this script. It should be:
awk 'BEGIN {FS="-"}{print $1,$2,$3}'
The rest looks ok but I could have easily missed something else.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2002 07:42 AM
06-14-2002 07:42 AM
Re: Date question
Clay, your corrected script worked the first time. I had no idea what all of it was doing so I ran each part of it starting from the right and working to the left to understand what was happening. I'm still confused but it works!
It took me a while to realize that $(awk) was the same thing as `awk`. Did you really just type those commands in and hit SUBMIT or did you cut and paste from an existing script?
Thanks very much,
Kris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2002 08:28 AM
06-14-2002 08:28 AM
Re: Date question
I just typed it in otherwise I probably wouldn't have missed that stupid '{'. I felt really dumb because I looked at that line for 30 seconds before I hit the button. And yes the $(command) syntax is now preferred over the older `command` syntax especially in cases where the $(commnds) are heavily nested.
No more points please, Clay