- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Manipulating dates in a POSIX shell (/usr/bin/sh)
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
тАО12-15-2006 12:50 AM
тАО12-15-2006 12:50 AM
Manipulating dates in a POSIX shell (/usr/bin/sh)
I have a shell script which needs to get today's date (i.e. 20061215) and add 1 day to this date, so I'd end up having 20061216 in a variable...
In Linux's gnu date command, I have `date -d "+1 day" +"%Y%m%d"` which works perfectly. Installing GNU Date on HPUX isn't an option for me... and I've already got my hole script in shell... so Perl isn't a friendly approach...
Has anyone done this?
Thanks, Pat
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-15-2006 12:54 AM
тАО12-15-2006 12:54 AM
Re: Manipulating dates in a POSIX shell (/usr/bin/sh)
date +%s
which gives me the epoch time.. so I'd end up with something like "1166123240". I could just add up "86400", which totals a day's worth, but then, how do I convert that to a date string?
thx again! Pat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-15-2006 12:55 AM
тАО12-15-2006 12:55 AM
Re: Manipulating dates in a POSIX shell (/usr/bin/sh)
Well, if you don't want Perl, I'd use Clay Stephenson's 'caljd' date manipulation utility!
You can download it from Merijn's website:
http://mirrors.develooper.com/hpux/
Regards!
...JRF...
- Tags:
- caljd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-15-2006 01:30 AM
тАО12-15-2006 01:30 AM
Re: Manipulating dates in a POSIX shell (/usr/bin/sh)
I have to add that Perl *is* such a straightforward approach for your task, though:
# perl -MPOSIX=strftime -le 'print strftime("%Y%m%d",localtime(time+(86400)))'
20061216
Plus, as you can see, the syntax mimics the GNU 'date' since both use the 'strftime' C library notation.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-15-2006 01:44 AM
тАО12-15-2006 01:44 AM
Re: Manipulating dates in a POSIX shell (/usr/bin/sh)
perl -MPOSIX -le 'print for strftime( "%Y%m%d", localtime(time + 86400) )'
which does the same.
Thanks!