Operating System - HP-UX
1753511 Members
5314 Online
108795 Solutions
New Discussion юеВ

Re: How to get a date after a specific number of days?

 
SOLVED
Go to solution
James R. Ferguson
Acclaimed Contributor

Re: How to get a date after a specific number of days?

Hi:

> 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...
Hein van den Heuvel
Honored Contributor

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. Please help me with this.


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.
James R. Ferguson
Acclaimed Contributor

Re: How to get a date after a specific number of days?

Hi (again):

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...

Vidhya B
Frequent Advisor

Re: How to get a date after a specific number of days?

Hi,

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.
Patrick Wallek
Honored Contributor

Re: How to get a date after a specific number of days?

Do you have the first line of the script as:

#!/usr/bin/perl

If not, make that the first line and then try again.
Hein van den Heuvel
Honored Contributor

Re: How to get a date after a specific number of days?

Ah, looks like you have the line "# cat ./fromwhen" as the first line in the script.
Remove that.
That was there just for clarification, not for inclusion.

Hein

James R. Ferguson
Acclaimed Contributor

Re: How to get a date after a specific number of days?

Hi (again):

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...