Operating System - HP-UX
1826909 Members
3046 Online
109705 Solutions
New Discussion

Display Yesterday Date from HP-UX

 
SOLVED
Go to solution

Display Yesterday Date from HP-UX

Your assistance is need.

How can I display yesterday date from HP-UX command prompt ?

TQVM
12 REPLIES 12
H.Merijn Brand (procura
Honored Contributor
Solution

Re: Display Yesterday Date from HP-UX

perl -le 'print scalar localtime time - 86400'
Enjoy, Have FUN! H.Merijn
Tom Geudens
Honored Contributor

Re: Display Yesterday Date from HP-UX

Hi,
See thread http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x583e7b8d1de3d5118ff40090279cd0f9,00.html

Regards,
Tom
A life ? Cool ! Where can I download one of those from ?
Rui Soares
Valued Contributor

Re: Display Yesterday Date from HP-UX

Hi!

You can use date format like:

$ date +%y/%d/%m

The thing is to get the previous day.

A rather lengthy solution would be:

month=`date +%m`
day=`date +%d`
year=`date +%Y
day=`expr $day - 1`
echo "$year/$day/$month"

Good Luck,

Rumagoso
Be Well
Kurt Beyers.
Honored Contributor

Re: Display Yesterday Date from HP-UX

the following command give the date of yesterday:

echo `(export TZ=XYZ+24; date "+%x")`

Kurt
H.Merijn Brand (procura
Honored Contributor

Re: Display Yesterday Date from HP-UX

That's wrong, that's the american format. It should be

l1:/u/usr/merijn 105 > perl -le '@d=localtime time-86400;$,="-";print$d[3],++$d[4],$d[5]+1900'
4-4-2002
l1:/u/usr/merijn 106 >
Enjoy, Have FUN! H.Merijn
Brian butler
Frequent Advisor

Re: Display Yesterday Date from HP-UX

Try this one
cal;date

BB
Reboot and give me twenty....
federico_3
Honored Contributor

Re: Display Yesterday Date from HP-UX

Compile the following C script (fdate.c)and use the command
fdate -1 ( to know the yesterday date)

#include
#include

main(argc, argv)
int argc;
char **argv;
{
time_t seconds;
struct tm *timeptr;

if(argc > 1)
{
seconds = time((long *)0) + atoi(argv[1])*24*60*60;
timeptr = localtime(&seconds);
fputs(asctime(timeptr), stdout);
exit(0);
}
else
exit(1);
}


Ciao
Federico
Kurt Beyers.
Honored Contributor

Re: Display Yesterday Date from HP-UX

This one is for procura:

echo `(export TZ=XYZ+24; date "+%d/%m/%y")`

gives the date of yesterday in the format DD/MM/YY

Kurt
James R. Ferguson
Acclaimed Contributor

Re: Display Yesterday Date from HP-UX

Hi:

The use of the following is commonly seen to compute yesterday's date:

# TZ=GMT+24 date +%m/%d/%y

Our European friends living around the Prime Meridian are the "lucky" ones who can use +-24 hours to exactly compute yesterday or tommorrow including the correct time.

If you look at the man pages for environ (5) you will note that offset is the value that must be added to local time to arrive at UTC (GMT). The offset takes the format hh[:mm[:ss]] where(hh)is any value from 0 through 23. The optional minutes (mm) and seconds (ss) fields are a value from 0 through 59. The hour field is required. If offset is preceded by a -, the time zone is east of the Prime Meridian. A + preceding offset indicates that the time
one is west of the Prime Meridian.

Notice, for example that while it is now 0749 hours on April 5 in the Eastern US, you cannot produce a date *and time* exactly 24-hours ago. To affect this, the computation would need to offset 29 hours (24+5), an invalid offset.

Regards!

...JRF...
H.Merijn Brand (procura
Honored Contributor

Re: Display Yesterday Date from HP-UX

JRF: perl -le 'print scalar localtime time - 29*60*60'

Kurt: Why? Though this will work in the shell (as requested), it'll barf in the (t)csh:

a5:/pro/3gl/GNU/gcc-3.0.4 229 > echo `(export TZ=XYZ+24; date "+%d/%m/%y")`
export: Command not found.
05/04/02
a5:/pro/3gl/GNU/gcc-3.0.4 230 > echo `(env TZ=XYZ+24 date "+%d/%m/%y")`
04/04/02
a5:/pro/3gl/GNU/gcc-3.0.4 231 >

but with the slashes, it -s still unclear to any european *how* he/she should parse that date. To be unambiguous, use YYYYMMDD

If I see dates with slashes, I have to *think*. I don't like to think with dates. Dates are complicated enough. Use month names :)
Enjoy, Have FUN! H.Merijn
SHABU KHAN
Trusted Contributor

Re: Display Yesterday Date from HP-UX

Hi Kamarul Zaman,
Assalaamu Alaikkum,

Here is another perl one-liner that you could use:

print `perl -e '@T=localtime(time-86400);printf("%02d/%02d/%02d",$T[4]+1,$T[3],($T[5]+1900)%100)'`

-Shabu
Gabriele FACCHINI
Frequent Advisor

Re: Display Yesterday Date from HP-UX

you can use this command:
TZ=PST-24 date +%D
bye
Gabriele
Gabriele Facchini