- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Adding 3 months to the output of the "date" co...
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
04-08-2004 03:00 AM
04-08-2004 03:00 AM
I am running the date command with the folling options:
date "+%Y%m%d%I%M%S"
How would I generate today date in this format with 3 months added to it.
Thanks is advance!!!
Tommy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2004 03:17 AM
04-08-2004 03:17 AM
Re: Adding 3 months to the output of the "date" command
JP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2004 03:19 AM
04-08-2004 03:19 AM
Re: Adding 3 months to the output of the "date" command
http://www.hpux.ws/merijn/caljd-2.2.pl
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
04-08-2004 05:45 AM
04-08-2004 05:45 AM
Re: Adding 3 months to the output of the "date" command
/opt/perl/bin/perl
use Time::Local 'timelocal_nocheck';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime(time);
print scalar localtime timelocal_nocheck $sec,$min,$hour,$mday,$mon+3,$year;
print "\n";
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2004 05:56 AM
04-08-2004 05:56 AM
SolutionGiven this specific request with the numeric input, and just adding monts, not days the calendar math becomes trivial. extract the month, add 3, overflow at 12 into the year.
For example in awk:
$ cat x
{
y=substr($0,1,4);
m=substr($0,5,2)+3;
if (m>12) { m=m%12; y++ };
x=substr($0,7,99);
printf("%d%02d%s\n",y,m,x);
}
$ date "+%Y%m%d%I%M%S" | awk -f x
20040708015008
$
$ date "+%Y%m%d%I%M%S"
20040408015013
just for grins!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2004 07:15 AM
04-08-2004 07:15 AM
Re: Adding 3 months to the output of the "date" command
date --date '3 months' +%Y%m%d%I%M%S
Frank.
P.S. You can get this date version from:
http://hpux.cs.utah.edu/hppd/hpux/Gnu/coreutils-5.2.0/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2004 09:46 AM
04-08-2004 09:46 AM
Re: Adding 3 months to the output of the "date" command
When adding 3 months to Jan-31, do you want it to become Apr-30 or May-1, because Apr-31 does not exist (but my hack will output just that!) Ditto for Nov-29 & 30.
Does you perhaps want to add 13 weeks?
Or do you know this will be run on the first of the month?
Just thought I'd warn you...
Hein