- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to get previous dates from date command
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
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
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
01-16-2003 11:29 PM
01-16-2003 11:29 PM
How to get previous dates from date command
How to get previous dates from date
command ? The requirement is to get any
previous dates with formats avail in
date command. Eg, if I pass parameter 0,
then today date, if -1, yesterday, if -2,
day before yesterday. If +2, then day after
tomorrow date.
Thanks
R. Ezhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2003 11:33 PM
01-16-2003 11:33 PM
Re: How to get previous dates from date command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2003 12:24 AM
01-17-2003 12:24 AM
Re: How to get previous dates from date command
date -d "5 days ago"
date -d "3 days"
date -d "3 months 2 days 6 hours ago"
Best regards...
Dietmar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2003 04:31 AM
01-17-2003 04:31 AM
Re: How to get previous dates from date command
The use of the following is commonly seen to compute yesterday's date:
# TZ=GMT+24 date +%m/%d/%y
If you are in Europe, living around the Prime Meridian you're in luck. There, you can use +-24 hours as an
The man pages for 'environ (5)' note that
Notice, for example, that while it is now 0730 hours on January 17 in the Eastern USA (EST), 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.
Clearly there are times during the day when "today" and "yesterday" would yield the same day. Caveat emptor.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2003 07:40 AM
01-17-2003 07:40 AM
Re: How to get previous dates from date command
2 days previous in
16-January-2003 format
DT=$(caljd.sh -e -O -S "-" $(caljd.sh -p 2))
echo "${DT}"
8 days from now in 01 25 2003 format
DT=$(caljd.sh $(caljd.sh -n 8))
echo "${DT}"
And this works over a much wider range of dates than the Gnu date command.
Invoke as caljd.sh -u for many options and examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2003 09:15 AM
01-17-2003 09:15 AM
Re: How to get previous dates from date command
Best regards...
Dietmar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2003 09:35 AM
01-18-2003 09:35 AM
Re: How to get previous dates from date command
Independently of the Time Zone you actually use, you can use the following sentence to get yesterday's date:
YESTERDAY="$( export TZ=$( date +%Z )+24 ; date )"
date +%Z gives the actual timezone used on the system. +24 makes a shift of 24 hours. setting the TZ environment variable to this, "date" will give you yesterday's date.
You'll just have to compute the shift (in hours) you put in the TZ to get the result you expect:
-( 24 * 0 ) = today,
-( 24 * -1 ) = yesterday,
-( 24 * -2 ) = the day before yesterday,
...
-( 24 * +1 ) = tomorrow,
-( 24 * +2 ) = the day after tomorrow,
and so on...
After, use date command option to get the result in the format you want.
regards,
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2003 08:56 PM
02-03-2003 08:56 PM
Re: How to get previous dates from date command
Thanks for your answer for my requirement.
I am sorry for late reply.
Your one line command seems to be easy.
As you said, I tried the following to get
date for fews days pervious and later date.
It is giving wrong result.
Please correct me if wrong.
date
result--> Mon Feb 3 23:31:46 EST 2003
outdate="$( export TZ=$( date +%Z )+(24*-3); date )"
echo $outdate
result--> Mon Feb 3 23:31:46 EST 2003
outdate="$( export TZ=$( date +%Z )+72; date )"
echo $outdate
result--> Mon Feb 3 23:31:46 EST 2003
Thanks
R. Ezhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2003 08:58 PM
02-03-2003 08:58 PM
Re: How to get previous dates from date command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2003 09:12 PM
02-03-2003 09:12 PM
Re: How to get previous dates from date command
Thanks for your reply.
Can you please attach your C program ?
I appreciate your help.
BTW, is there any good Web site for
Unix-C for technical knowledge sharing
and forums ?
Thanks
R. Ezhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2003 06:20 AM
02-04-2003 06:20 AM
Re: How to get previous dates from date command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2003 09:10 AM
02-04-2003 09:10 AM
Re: How to get previous dates from date command
I'm also interested in this topic, and I tried to reset TZ to get tomorrow and yesterday, but it seemed that this method doesn't work for offset more than 24 ours, i.e, $TZ-24 gives me tomorrow, and $TZ+24 gives me yesterday, BUT, $TZ+72 gives me today again! any idea ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2003 09:19 AM
02-04-2003 09:19 AM
Re: How to get previous dates from date command
With your +72 offset the TZ is likely to be ignored completely. :-)
See environ(5). The offset needs to be in the 0..23 range.
Best regards...
Dietmar.