Re: tomorrows date

From: Robert Binkley (rbinkl@COMCAST.NET)
Date: Wed Dec 10 2003 - 10:18:18 EST


>From the command-line:
======================
[Using Perl]
To print yesterday's date:

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

To print tomorrow's date:

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

[the TZ trick]
If the system is located WEST of the Greenwich Meridian (ie - in the
Americas), you can determine tomorrow's date by temporarily subtracting
24 hours from the timezone offset, like so:

  $ offset=`echo $TZ | tr -d '[A-Z+]'`
  $ new_offset=`echo $offset - 24 | bc`
  $ TZ=`echo $TZ | sed "s/[+-]\{0,1\}[1-9][0-9]\{0,1\}/$new_offset/` \
   date +%D

Unfortunately, in this part of the world, a similar method method cannot
be used to obtain yesterday's date, because, under HP-UX, the timezone
offset can not be greater than +24.

If the system is located EAST of the Greenwich Meridian (ie - in Europe),
you can determine yesterday's date by temporarily adding 24 hours to the
timezone offset, like so:

  $ offset=`echo $TZ | tr -d '[A-Z+]'`
  $ new_offset=`echo $offset + 24 | bc`
  $ TZ=`echo $TZ | sed "s/[+-]\{0,1\}[1-9][0-9]\{0,1\}/$new_offset/` \
    date +%D

Unfortunately, in this part of the world, a similar method method cannot
be used to obtain tomorrow's date, because, under HP-UX,AIX the timezone
offset cannot be less than -24.

[GNU date]
The GNU date command has a powerful -d option that the HP-UX date command
does not have. You can do things like:

  $ date -d yesterday
  $ date -d '2 days ago'
  $ date -d '1 week ago'
  $ date -d tomorrow
  $ date -d '2 days'
  $ date -d '1 week'

Robert Lee Binkley
5009 Silver Oak
Sherwood ark 72120
** rbinkl@comcast.net <mailto:rbinkl@comcast.net>
** ************
** ************

-----Original Message-----
From: IBM AIX Discussion List [mailto:aix-l@Princeton.EDU]On Behalf Of
Shawn Bierman
Sent: Wednesday, December 10, 2003 8:53 AM
To: aix-l@Princeton.EDU
Subject: Re: tomorrows date

What are you saying? I do not need yesterdays date. Only tomorrow's. I
did have the time zone wrong, its actually CST. But does that allow for
daylight savings and leap years etc?

ksh TZ=CST-24 date +%m%d%y

-shawn

>>> rick.renison@EDS.COM 12/9/03 9:13:25 PM >>>
It doesn't always give yestday's date.
eg. TZ=XXX-24 gives tomorrow's (not yesterday) date/time if you are in
England.
If you want your own time zone, replace the [-][0-9]* with the value +24
hours (yes, a "+" value)
eg. if EST5EDT, use TZ=xxx29
eg. if JST-9, use TZ=xxx15

If you want daylight savings time, append the 'dst' info to the TZ variable.
(see man environment)

...Rick

> -----Original Message-----
> From: IBM AIX Discussion List [mailto:aix-l@Princeton.EDU]On Behalf Of
> Shawn Bierman
> Sent: December 9, 2003 4:06 PM
> To: aix-l@Princeton.EDU
> Subject: tomorrows date
>
>
> Is a statement like this always going to be correct?
>
> ksh TZ=SCG-24 date +%m%d%y
>
>
> Does it allow for leap years, time zone changes etc...?
>
> I just want it to give tomorrows date.
>
> -shawn
>



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:17:23 EDT