HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- yesterday's date question
Operating System - HP-UX
1834903
Members
2559
Online
110071
Solutions
Forums
Categories
Company
Local Language
back
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
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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-18-2002 04:30 AM
02-18-2002 04:30 AM
after perusing faq, list servs etc I cant seem to get the following to work:
sh -c "TZ=$(date +%Z)+24;export TZ;date '+%a %b %e'"
At 8 o'clock last night, it reported that yesterday was Feb 17, and the regular date command showed Feb 17.
My TimeZone it EST5EDT.
Is there anyway to get this to work 24X7?
sh -c "TZ=$(date +%Z)+24;export TZ;date '+%a %b %e'"
At 8 o'clock last night, it reported that yesterday was Feb 17, and the regular date command showed Feb 17.
My TimeZone it EST5EDT.
Is there anyway to get this to work 24X7?
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 04:38 AM
02-18-2002 04:38 AM
Solution
Hi:
No. Our European friends living around the Prime Meridian are the "lucky" ones who can use +-24 hours to exactly compute yesterday or tommorrow including the correct time.
If you look at the man pages for environ (5) you will note that offset is the value that must be added to local time to arrive at UTC (GMT). Offset takes the format hh[:mm[:ss]]
where (hh)is any value from 0 through 23. The optional minutes (mm) and seconds (ss) fields are a value from 0 through 59. The hour field is required. If offset is preceded by a -, the time zone is east of the Prime Meridian. A + preceding offset indicates that the time
one is west of the Prime Meridian.
Notice, for example that while it is now 0745 hours on February 18 in the Eastern US, you cannot produce a date *and time* exactly 24-hours ago. To affect this, the computation would need to offset 29 hours (24+5), an invalid offset.
Regards!
...JRF...
No. Our European friends living around the Prime Meridian are the "lucky" ones who can use +-24 hours to exactly compute yesterday or tommorrow including the correct time.
If you look at the man pages for environ (5) you will note that offset is the value that must be added to local time to arrive at UTC (GMT). Offset takes the format hh[:mm[:ss]]
where (hh)is any value from 0 through 23. The optional minutes (mm) and seconds (ss) fields are a value from 0 through 59. The hour field is required. If offset is preceded by a -, the time zone is east of the Prime Meridian. A + preceding offset indicates that the time
one is west of the Prime Meridian.
Notice, for example that while it is now 0745 hours on February 18 in the Eastern US, you cannot produce a date *and time* exactly 24-hours ago. To affect this, the computation would need to offset 29 hours (24+5), an invalid offset.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 06:53 AM
02-18-2002 06:53 AM
Re: yesterday's date question
This tiny C program will do exactly what you want.
#include
#include
#define SECONDS_IN_A_DAY 86400
int main ()
{
time_t t;
char buffer[BUFSIZ];
time(&t);
t -= SECONDS_IN_A_DAY;
strftime(buffer, BUFSIZ, "%a %b %e", localtime(&t));
printf("%s\n", buffer);
}
#include
#include
#define SECONDS_IN_A_DAY 86400
int main ()
{
time_t t;
char buffer[BUFSIZ];
time(&t);
t -= SECONDS_IN_A_DAY;
strftime(buffer, BUFSIZ, "%a %b %e", localtime(&t));
printf("%s\n", buffer);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 11:38 AM
02-18-2002 11:38 AM
Re: yesterday's date question
Hi,
There is a perl one-liner to calculate yesterday's date
/usr/local/bin/perl -e
'@T=localtime(time-86400);printf("%02d/%02d/%02d",$T[4]+1,$T[3],($T[5]+1900)
%100)'
You could change it to display in whatever format you like..
Hope this helps..
-Shabu
There is a perl one-liner to calculate yesterday's date
/usr/local/bin/perl -e
'@T=localtime(time-86400);printf("%02d/%02d/%02d",$T[4]+1,$T[3],($T[5]+1900)
%100)'
You could change it to display in whatever format you like..
Hope this helps..
-Shabu
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP