- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- assign yesterday's date in ksh
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
тАО10-17-2010 10:54 PM
тАО10-17-2010 10:54 PM
assign yesterday's date in ksh
I am using ksh. whether there is any command
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-17-2010 11:06 PM
тАО10-17-2010 11:06 PM
Re: assign yesterday's date in ksh
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=9251
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-18-2010 05:04 AM
тАО10-18-2010 05:04 AM
Re: assign yesterday's date in ksh
# YESTERDAY=$(perl -MPOSIX -le 'print strftime "%b %e",localtime(time-(60*60*24))')
# echo "${YESTERDAY}"
Oct 17
This will compute yesterday's date in your local timezone.
The Perl POSIX module allows you to use the 'strftime()' function with the same formatting directives you find in its manpages [ 'strftime(3C)' ]. These directives are the same as you use with the 'date' command. The '%e' specification yields the day of the month with space fill whereas the '%d' uses zero-fill.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2010 02:19 PM
тАО10-20-2010 02:19 PM
Re: assign yesterday's date in ksh
In order to do this in shell, I think you can manipulate the TZ variable - just add the proper number of hours to your current timezone offset, like so:
gbrhpq$ echo $TZ
EST5EDT
gbrhpq$ date
Wed Oct 20 18:02:19 EDT 2010
gbrhpq$ expr 5 + 18 + 1
24
gbrhpq$ TZ=EST24EDT
gbrhpq$ date
Tue Oct 19 23:08:09 EDT 2010
gbrhpq$
It looks like the trick is adding just enough hours to the timezone offset to take you back to sometime after 23:00 (11:00pm) the day before. If you add more, it goes back to the current date and time:
gbrhpq$ TZ=EST25EDT
gbrhpq$ date
Wed Oct 20 18:17:09 EDT 2010
gbrhpq$
I'm not sure if this will work at 7:00pm in the same way, though. We'll see...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2010 03:16 PM
тАО10-20-2010 03:16 PM
Re: assign yesterday's date in ksh
> A not-so-subtle way of saying scripts should be in Perl, not sh.
There was no subtle message in what I wrote. I wasn't invoking a holy war; rather I was pointing out a pitfall that isn't necessarily apparent at first blush.
> In order to do this in shell, I think you can manipulate the TZ variable
Sure, fraught with peril. Oddly, if you look at *my* response to this technique in the link that Anshumali posted in this thread, you will see *why* using the TZ variable is a slippery slope.
Regards!
...JRF...