- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Date computation in a shell script
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
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
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
тАО09-27-2001 02:28 PM
тАО09-27-2001 02:28 PM
Is there a way to add/subtract days using date function in a shell script ?
Please don't tell me that I have to write lengthy unix script .
for e.g I want to add 2 days to the current date in a shell script !!!
i.e expr "`date + 2`" or something like that
Thanks in advance
Bala
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2001 02:36 PM
тАО09-27-2001 02:36 PM
Solutionhttp://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0x5fc3854994d9d4118fef0090279cd0f9,00.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2001 02:39 PM
тАО09-27-2001 02:39 PM
Re: Date computation in a shell script
I have a simple utility that makes this duck soup. The script is complicated but it's already written - so who cares.
The idea is that we convert today's date to a true Jukian Day (~ num of days since 4004 BCE) and add 2 to it and then send that number back in to the script.
TODAY=`caljd.sh`
NEXTDATE=$((${TODAY} + 2))
NEWDATE=`caljd.sh ${NEXTDATE}`
echo ${NEWDATE}.
The attached script does all the hard work and if you execute caljd.sh -u it will display the full usage. The neat thing about this method is that it will work across months, leap years,
past or future, ...
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2001 02:41 PM
тАО09-27-2001 02:41 PM
Re: Date computation in a shell script
perl -e 'print scalar localtime (time +2 * 86400),"\n"'
will add 2 days to the current date
perl -e 'print scalar localtime (time -2 * 86400),"\n"'
will subtract 2 days from the current date
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2001 02:45 PM
тАО09-27-2001 02:45 PM
Re: Date computation in a shell script
Unfortunately there is no single command to do arthmetic on dates. There are quite a number ways to do this. As perl is almost there on unix systems, you can use the method suggested by David in the thread
http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0x2fc2854994d9d4118fef0090279cd0f9,00.html
or you can use the logic behind it.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2001 02:53 PM
тАО09-27-2001 02:53 PM
Re: Date computation in a shell script
Thanks again
Bala