- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: extract previous date
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
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
тАО02-04-2005 07:24 AM
тАО02-04-2005 07:24 AM
extract previous date
I need to extract the previous day's date in the form of mmddyyyy in my script.
Can anyone please help me.
Thanks,
Pat
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2005 07:29 AM
тАО02-04-2005 07:29 AM
Re: extract previous date
please cruise to this page and scroll down to the bottom. You will see the links to download either version.
http://www.hpux.ws/merijn/
Hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2005 07:41 AM
тАО02-04-2005 07:41 AM
Re: extract previous date
YESTERDAY=$(caljd.sh -s $(caljd.sh -p 1))
echo "Yesterday was ${YESTERDAY}"
Invoke as caljd.sh -u for full usage and examples.
- Tags:
- caljd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2005 08:25 AM
тАО02-04-2005 08:25 AM
Re: extract previous date
YESTERDAY=$(perl -e '($mday,$mon,$year) = (localtime(time() - 86400)) [3,4,5]; printf("%02d%02d%04d\n",$mon + 1,$mday,$year + 1900)')
echo "Yesterday was ${YESTERDAY}"
If I got all the ()'s,[]'s, and quotes right that ought to work but I think the caljd.sh solution is much more readable.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2005 09:51 AM
тАО02-04-2005 09:51 AM
Re: extract previous date
LAST_MONTH=$((`date +%m` -1))
case "$LAST_MONTH"
in
0) LM=Dec;;
1) LM=Jan;;
2) LM=Feb;;
3) LM=Mar;;
4) LM=Apr;;
5) LM=May;;
6) LM=Jun;;
7) LM=Jul;;
8) LM=Aug;;
9) LM=Sep;;
10) LM=Oct;;
11) LM=Nov;;
12) LM=Dec;;
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2005 10:00 AM
тАО02-04-2005 10:00 AM
Re: extract previous date
perl -MPOSIX -e 'print POSIX::strftime("%Y%m%d", localtime(time - 86400));'
Ed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2005 10:06 AM
тАО02-04-2005 10:06 AM
Re: extract previous date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2005 05:04 AM
тАО02-07-2005 05:04 AM
Re: extract previous date
Thanks for all the help. I have used Clay's solution which works absolutely fine.
Clay - Can you please suggest me how to use your script in case I want yesterday's date to be in the format mmddyy (020605).
Thanks,
Pat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2005 06:45 AM
тАО02-07-2005 06:45 AM
Re: extract previous date
YESTERDAY=$(perl -e '($mday,$mon,$year) = (localtime(time() - 86400)) [3,4,5]; printf("%02d%02d%02d\n",$mon + 1,$mday,$year % 100)')
echo "Yesterday was ${YESTERDAY}"
... and here's the caljd.sh method:
YESTERDAY=$(caljd.sh -s -C $(caljd.sh -p 1))
echo "Yesterday was ${YESTERDAY}"
If you had invoked caljd.sh as caljd.sh -u, you would have seen the "-C" option and been able to answer your own question.