- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to get a date after a specific number of d...
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
02-16-2011 11:43 PM
02-16-2011 11:43 PM
My date is in the format mmddyy. I need to know the date after say 25 days. Is there any specific command which can accompolish this?
Thanks in Advance!!
Solved! Go to Solution.
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2011 11:59 PM - last edited on 09-02-2011 12:46 PM by Kevin_Paul
02-16-2011 11:59 PM - last edited on 09-02-2011 12:46 PM by Kevin_Paul
Re: How to get a date after a specific number of days?
Please find the below thread in that there is a script from A. Clay Stephenson.kindly check whether it help you or not?
http://h30499.www3.hp.com/t5/System-Administration/favourite-sysadmin-scripts-you-always-keep-around/m-p/4844855#M393717
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2011 12:49 AM
02-17-2011 12:49 AM
Re: How to get a date after a specific number of days?
could be with crontab?
Regards, Jorge
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2011 01:10 AM
02-17-2011 01:10 AM
Re: How to get a date after a specific number of days?
Thank you all for your replies.
Is there any other specific command to do that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2011 01:55 AM
02-17-2011 01:55 AM
Solutionhttp://hpux.connect.org.uk/hppd/hpux/Gnu/coreutils-8.6/
Don't miss the run-time dependencies required as well.
With GNU date installed you can run:
date --d "+25 days" +%m%d%y
You'll need to put the path to the GNU date command in front of that, otherwise it will just invoke the HP-UX date command.
No doubt the perl-mongers on the forums will also be able to give you a perl one-liner for this as well.
HTH
DUncan
I am an HPE Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2011 02:37 AM
02-17-2011 02:37 AM
Re: How to get a date after a specific number of days?
This might help you. Try this.
Result=$(perl -MPOSIX -le 'print strftime "%d%b",localtime(time+(60*60*24*25))')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2011 05:10 AM
02-17-2011 05:10 AM
Re: How to get a date after a specific number of days?
You might note that by using Perl and the 'strftime' function you can choose any date format you want. The format directives are equivalent to those you are familiar with in the 'date' command. Of course, see too the manpages for 'strftime(3C)'. For example:
# perl -MPOSIX -le 'print strftime "%d %b",localtime(time+(60*60*24*25))'
14 Mar
# perl -MPOSIX -le 'print strftime "%m/%d/%Y",localtime(time+(60*60*24*25))'
03/14/2011
# perl -MPOSIX -le 'print strftime "%m/%d/%Y %H:%M",localtime(time+(60*60*24*25))'
03/14/2011 09:08
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2011 09:50 PM
02-17-2011 09:50 PM
Re: How to get a date after a specific number of days?
That perl scripting really worked. Thanks a lot:)
But I am able to find the date after 25 days from today's date. Is there anyother modification I can do so that the perl will take my input?
Actually I need to find the date after 25 days from a specific date but not from today's date.Kindly help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2011 06:36 AM
02-18-2011 06:36 AM
Re: How to get a date after a specific number of days?
> Actually I need to find the date after 25 days from a specific date but not from today's date.
You can begin with something like this an embellish as you like. Notice that I require the input as YYYYMMDD.
# cat ./fromwhen
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(strftime);
use Time::Local;
my $date = shift or die "Date (YYYYMMDD) expected\n";
die "YYYMMDD expected\n" unless
my ( $yyyy, $mm, $dd ) = ( $date =~ /(\d{4})(\d\d)(\d\d)/ );
my $when = shift or die "Number of days in future expected\n";
my $secs = timelocal(0, 0, 0, $dd, $mm-1,$yyyy );
print strftime "%Y/%m/%d\n",localtime($secs+(60*60*24*$when));
1;
...run as (for example):
# .l/fromwhen 20110218 13
2011/03/03
...which yields the date thirteen (13) days from February 18, 2011.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2011 05:57 AM
03-18-2011 05:57 AM
Re: How to get a date after a specific number of days?
Thankyou for the replies.
I tried the script. I don't how exactly to run that script. I found no good results. I think I have done some mistake. Please help me with this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2011 06:18 AM
03-18-2011 06:18 AM
Re: How to get a date after a specific number of days?
> I tried the script. I don't how exactly to run that script. I found no good results. I think I have done some mistake.
Copy&paste the script I posted into a file named as you wish. Set execute permissions and then run it passing two arguments --- the first is the YYYYMMDD from which you want to count. The second argument is the number of days from the first argument date that you want to compute.
For example, I called the script 'fromwhen'. Hence:
# cd <script directory>
# chmod 555 ./fromwhen
# ./fromwhen 20110318 25
2011/04/12
...which shows that April 12 is 25-days from March 18.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2011 06:18 AM
03-18-2011 06:18 AM
Re: How to get a date after a specific number of days?
Hmmm. It works for me.
It came with usage example and has 'help' build in.
copy & paste into a (text) file.
In the example: "fromwhen"
Make executable
chmod +x fromwhen
Run it with 2 arguments... a date and days
Example:
./fromwhen 20080101 32
2008/02/02
Maybe your perl is not in the standard place?
Try 'which perl'
Anyway...
>> I found no good results.
So what did you get? Error message? Unexpected values? Show and tell!
We can not read your mind, nor your screen.
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2011 06:26 AM
03-18-2011 06:26 AM
Re: How to get a date after a specific number of days?
If your Perl isn't in '/usr/bin' simply change the 'shebang' line at the top of the script to point to the correct location.
Most commonly, you declare '#!/usr/bin/perl' in your scripts and simply symlink the Perl binary accordingly. This allows your scripts to make a static declaration while your binaries are installed in various subdirectories of '/opt' or '/usr' as your needs dictate.
Doing a 'whereis perl' is one way to find where 'perl' is. Another option is to use this for the 'shebang' (interpreter line):
#!/usr/bin/env perl
If you do this, the Perl interpreter will be "automatically" located for you.
As always, a problem description of "it doesn't work" doesn't provide any useful information. Be specific. Exactly what did you do and exactly what were the results you obtained. A good problem description leads to a good resolution.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2011 07:19 AM
03-18-2011 07:19 AM
Re: How to get a date after a specific number of days?
I tried running the script in the way you mentioned.
Here is my error message:
#./fromwhen 20110318 02
./fromwhen[3]: use: not found.
./fromwhen[4]: use: not found.
./fromwhen[5]: Syntax error at line 5 : `(' is not expected.
Here is my whereis perl output :
#whereis perl
perl: /usr/bin/perl /opt/dsau/bin/perl /opt/dsau/sbin/perl /opt/perl/bin/perl /opt/perl_32/bin/perl /opt/perl_64/bin/perl /opt/VRTSperl/bin/perl /usr/eccperl/bin/perl /opt/perl/man/man1/perl.1 /opt/perl_32/man/man1/perl.1 /opt/perl_64/man/man1/perl.1 /opt/VRTSperl/man/man1/perl.1
Kindly help me with this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2011 07:22 AM
03-18-2011 07:22 AM
Re: How to get a date after a specific number of days?
#!/usr/bin/perl
If not, make that the first line and then try again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2011 07:26 AM
03-18-2011 07:26 AM
Re: How to get a date after a specific number of days?
Remove that.
That was there just for clarification, not for inclusion.
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2011 08:53 AM
03-18-2011 08:53 AM
Re: How to get a date after a specific number of days?
If you don't have an interpreter ("shebang") line in a file, then the shell is assumed.
Hence, if you don't have:
#!/usr/bin/perl
...as the first line of the script, then:
# /usr/bin/sh
...is assumed, and that leads to errors as the shell interpreter attempts to parse Perl syntax!
_Always_ begin your scripts with the interpreter declaration!
Regards!
...JRF...