Operating System - HP-UX
1825161 Members
2258 Online
109679 Solutions
New Discussion юеВ

Shell script to generate yesterday date

 
Marco_ALT
Esteemed Contributor

Shell script to generate yesterday date

Hi

i need to generate the date of yesterday with the following format:

--

like 14-Oct-09

thanks
10 REPLIES 10
Marco_ALT
Esteemed Contributor

Re: Shell script to generate yesterday date

how i can get this scipt

http://www.hpux.ws/merijn/caldj-2.3.sh

Kenan Erdey
Honored Contributor

Re: Shell script to generate yesterday date

Hi,

yesterday=`TZ=aaa24 date +"%d-%b-%y"`
echo $yesterday;
Computers have lots of memory but no imagination
Hakki Aydin Ucar
Honored Contributor

Re: Shell script to generate yesterday date

Attached my favorite yesterday shell, you can use it:
Dennis Handly
Acclaimed Contributor

Re: Shell script to generate yesterday date

Suraj K Sankari
Honored Contributor

Re: Shell script to generate yesterday date

Hi,
Here is the command

$ dt=`TZ=$TZ-24 date '+%d-%b-%y'`;echo $dt
15-Oct-09


Suraj
Suraj K Sankari
Honored Contributor

Re: Shell script to generate yesterday date

Hi again,
Sorry my previous post is for tomorrows here is the yesterday one

$ date
Wed Oct 14 03:57:40 EDT 2009

$ dt=`TZ=$TZ+24 date '+%d-%b-%y'`;echo $dt
13-Oct-09

Suraj
Laurent Menase
Honored Contributor

Re: Shell script to generate yesterday date

#include
#include
main()
{
long t;
char buf[256];
t=time(0)-24*3600;
strftime(buf,255,"%d-%b-%y", localtime(&t));
printf("%s\n",buf);
}
James R. Ferguson
Acclaimed Contributor

Re: Shell script to generate yesterday date

Hi:

Using the 'TZ" variable and adding or subtracting hours from it only works for UTC time.

One totally accurate, safe way to do what you want is to use Perl. For your specification:

# perl -MPOSIX -le 'print strftime "%d-%b-%y",localtime(time-(60*60*24))'
13-Oct-09

You can use the same formatting directives to the strftime() function that you would use with the 'date' command.

Regards!

...JRF...
Hakki Aydin Ucar
Honored Contributor

Re: Shell script to generate yesterday date

>Dennis: >how I can get this scipt
http://www.hpux.ws/merijn/caldj-2.3.sh

needs userid and password !