- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Can I get yesterday's date in a unix 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-03-2006 03:54 PM
тАО09-03-2006 03:54 PM
Re: Can I get yesterday's date in a unix script?
simply type this:
DTE=$(date +%Y%m%d -1)
((Y=DTE - 1))
print $Y
20060902
print $DTE
20060903
Done...its as simple as that!
-----------------------------------
I completely agree this is a simple solution. Try it on the first day of the month (or better the first day of the year).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2006 12:16 AM
тАО09-05-2006 12:16 AM
Re: Can I get yesterday's date in a unix script?
I had a solution similar to Jody's. On
Sep 1 , it gave me yesterday's date 20060900. That's what sent me here in the first place. I played with your idea of passing a multiple of 86400 from Unix shell to Perl on command line. I am reasonably good in Shell but not in Perl. Although I settled on your caljd.sh, still I want to know how you pass a Shell variable to Perl.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2006 12:27 AM
тАО09-05-2006 12:27 AM
Re: Can I get yesterday's date in a unix script?
I initiated this question as a continuation of a thread started in 2004 because it relates to the original question AND the thread was not closed by the author. Now I am looking around to assign points to well deserved replies. But I can't. Does any body know how I can assign points to the replies to my question. Should I have started a new thread in the first place? I thought it will be easier explaining my question as a extension of an existing question.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2006 12:35 AM
тАО09-05-2006 12:35 AM
Re: Can I get yesterday's date in a unix script?
Here's a simple Perl snippet that will find yesterday's date, or a day n-days ago:
# perl -le 'print scalar localtime(time-(86400*$ARGV[0]))' 2
...will return a date two (2) days ago. If you don't pass any argument, the current local date and time is returned.
You could pass a shell variable thusly:
# n=2;perl -le 'print scalar localtime(time-(86400*$ARGV[0]))' $n
...and if you want to use this to find future days:
# n=-2;perl -le 'print scalar localtime(time-(86400*$ARGV[0]))' -- $n
In the last case, note the '--' to signal that the negative value that follows is not a switch, but rather an argument.
Regards!
...JRF...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2006 01:06 AM
тАО09-05-2006 01:06 AM
Re: Can I get yesterday's date in a unix script?
Perfect. The '$n' is what I played with and failed. I now have two perfect solutions.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2006 07:16 AM
тАО09-29-2006 07:16 AM
Re: Can I get yesterday's date in a unix script?
my $yesterday=`date -d 'yesterday' +%Y%m%d`
Jyothi
- « Previous
-
- 1
- 2
- Next »