- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- date X months ago
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
09-21-2003 12:14 AM
09-21-2003 12:14 AM
Just wanted to ask, not to invent the wheel again, what is the *shortest* way in shell script to get date X months ago?
If today is 2003/09/21, I want to get 2003/06/21?
thanx!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2003 02:10 AM
09-21-2003 02:10 AM
SolutionIt is the prior version of a great script from A. Clay Stephenson.
More current versions available on merijn's site which I have not bookmarked.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2003 03:07 AM
09-21-2003 03:07 AM
Re: date X months ago
It could be my browser, but the famous caljd.sh posted by Stephen Protter is unreadable over here. However, it should be the easiest thing to search for in this forum.
caljd.sh accepts various parameters for e.g. asking for the date 90 days ago, as in this example:
# PREV90=$(caljd.sh -y -s $(caljd.sh -p 90))
# echo $PREV90
20030623
but I dont think that you can supply a number of months as parameter. If months ago is 2 and today is 2003/04/30. What would then be the correct answer?
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2003 06:40 PM
09-21-2003 06:40 PM
Re: date X months ago
Here is a simple C program i wrote to get date say X days back. It can be modified to get date in the desired format and needs a input variable as day.
Say you want to get date 3 days back you run it as
a.out 3
(a.out is the compiled program)
#include
#include
#include
#include
#include
int tm, day, tm1;
char *date, *dat;
main(argc, argv)
int argc;
char *argv[];
{
time(&tm);
day=atoi(argv[1]);
day=(day*24*60*60);
date = ctime(&tm);
printf("The Present Date & Time is : %s", date);
tm1=(tm - day);
dat = ctime(&tm1);
printf("The Date & Time %s days Back was: %s", argv[1],dat);
}
Cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2003 03:38 PM
09-22-2003 03:38 PM
Re: date X months ago
gnu_date -d "3 months ago"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2003 01:43 AM
09-23-2003 01:43 AM