- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell Script (Get old date from current 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
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
11-30-2004 08:19 PM
11-30-2004 08:19 PM
old date from current date.
For example,
I can get the current by `/usr/bin/date +%Y%m%d`.
How to get the old date(14 days before) from above current date?
Thanks for advise.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2004 08:27 PM
11-30-2004 08:27 PM
Re: Shell Script (Get old date from current date)
In shell flavor :
http://mirrors.develooper.com/hpux/caljd-2.23.sh
or perl one :
http://mirrors.develooper.com/hpux/caljd-2.2.pl
It's a you-can-do-anything-with-date program.
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2004 08:42 PM
11-30-2004 08:42 PM
Re: Shell Script (Get old date from current date)
Is there another way to slove this question?
Chen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2004 08:52 PM
11-30-2004 08:52 PM
Re: Shell Script (Get old date from current date)
date '14 days ago'
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2004 03:08 AM
12-01-2004 03:08 AM
Re: Shell Script (Get old date from current date)
#!/usr/bin/sh
DATEMINUS14=$(caljd.sh -y -s $(caljd.sh -p 14))
echo "14 days ago was ${DATEMINUS14}"
All of the calculations are done in just two functions cal_jdate and jdate_cal so if you like you can simply yank those out and put themn in your script. Invode as caljd.sh -u for full usage and many examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2004 03:26 AM
12-01-2004 03:26 AM
Re: Shell Script (Get old date from current date)
enjoy,
manuel
today
$ date '+%b-%d'
Aug-13
- 1 day
$ perl -e 'print scalar localtime (time -1 * 86400),"\n"'
Thu Aug 12 14:03:33 2004
- 13 days
$ perl -e 'print scalar localtime (time -13 * 86400),"\n"'
Sat Jul 31 14:04:01 2004
yesterday
$ perl -e 'print scalar localtime (time -1 * 86400),"\n"' | awk '{print $2"-"$3}'
Aug-12
tomorrow
$ perl -e 'print scalar localtime (time +1 * 86400),"\n"' | awk '{print $2"-"$3}'
Aug-14
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2004 11:13 AM
12-01-2004 11:13 AM
Re: Shell Script (Get old date from current date)
But it doesnot work on my server.
My server's OS is HP-UX 11.00.
Chen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2004 11:35 AM
12-01-2004 11:35 AM
Solution#!/usr/bin/sh
DT14BEFORE=$(perl -e '($year,$mon,$day) = (localtime(time() - (14 * 86400)))[5,4,3]; printf("%04d%02d%02d\n",$year + 1900,$mon + 1,$day)') # all of this is one line
echo "14 Days ago = ${DT14BEFORE}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2004 11:52 AM
12-01-2004 11:52 AM
Re: Shell Script (Get old date from current date)
I have confirmed it work.
Chen Yingjie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2004 11:18 PM
12-01-2004 11:18 PM
Re: Shell Script (Get old date from current date)
there is a little script that calculates the date in the past.
# Comand line argument: Amount of days in the past
PAST=$1
DATE=`date +%Y%m%d`
DATE=`expr $DATE - $PAST`
YEAR=`echo $DATE | cut -b 1,2,3,4`
DAY=`echo $DATE | cut -b 7,8`
MONTH=`echo $DATE | cut -b 5,6`
if [ "$DAY" = "00" ]
then
DATE=`expr $DATE - 100`
MONTH=`echo $DATE | cut -b 5,6`
if [ "$MONTH" = "00" ]
then
MONTH=12
DATE=`expr $DATE - 10000`
YEAR=`echo $DATE | cut -b 1,2,3,4`
fi
x=`cal $MONTH $YEAR`
DAY=`(for i in $x; do echo $i; done;) | tail -1`
fi
YEAR=`echo $YEAR | cut -b 3,4`
HOUR=`date +%H`
MINUTE=`date +%M`
# Here you can change the output
DATE="${MONTH}${DAY}${HOUR}${MINUTE}${YEAR}"
echo $DATE
Regards
Markus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2004 02:58 AM
12-02-2004 02:58 AM
Re: Shell Script (Get old date from current date)
manny> perl -e 'print scalar localtime (time -1 * 86400),"\n"'
Wed Dec 1 07:59:25 2004
manny> date
Thu Dec 2 07:59:28 PST 2004
maybe it's the version of perl:
manny> perl -v
This is perl, v5.6.0 built for 9000/777-hpux
the following is from an 11.00 box:
> perl -e 'print scalar localtime (time -1* 86400),"\n"'
Wed Dec 1 08:01:42 2004
> date
Thu Dec 2 08:01:44 PST 2004
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2004 06:39 PM
12-02-2004 06:39 PM