*BSD News Article 35072


Return to BSD News archive

Xref: sserve comp.unix.bsd:14745 comp.unix.misc:13673 comp.unix.programmer:19605 comp.unix.questions:54293
Newsgroups: comp.unix.bsd,comp.unix.misc,comp.unix.programmer,comp.unix.questions
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!bunyip.cc.uq.oz.au!munnari.oz.au!constellation!convex!hermes.oc.com!news.unt.edu!cs.utexas.edu!swrinde!pipex!sunic!trane.uninett.no!eunet.no!nuug!EU.net!uunet!hobbes!earth.armory.com!spcecdt
From: spcecdt@armory.com (John DuBois)
Subject: Re: Q:  How can I get yesterday's date?
Organization: The Armory
Date: Sun, 28 Aug 1994 03:39:50 GMT
Message-ID: <Cv87IF.1yo@armory.com>
References: <Pine.3.89.9408160216.A15886-0100000@worf.uwsp.edu> <32q00b$9vn@daphne.ecmwf.co.uk> <32qdqm$bnv@access1.digex.net> <33ft6h$ecf@trantjern.ifi.uio.no>
Sender: news@armory.com (Usenet News)
Nntp-Posting-Host: deeptht.armory.com
Lines: 25

p10:~> echo $TZ
PST8PDT
p10:~> date
Sat Aug 27 20:06:31 PDT 1994
p10:~> TZ=PST32PDT date
Fri Aug 26 20:06:35 PDT 1994

The numeric part of TZ was increased by 24 to go back one day in time.  Note,
the PST...PDT are needed to get the right timezone into the date.  Also, the
existance of the part after the numeric offset tells the time functions that
the local area does daylight savings time:
p10:~> TZ=32 date
Fri Aug 26 19:09:30  1994
p10:~> TZ=32x date
Fri Aug 26 20:09:40  1994

This scheme wouldn't work with time functions that do an explicit bounds check
on the numeric offset (insisting that it be <24), but I've never run into such.
You can give a positive or negative offset, including minute & second
components, to find the date an arbitrary amount of time (within the bounds of
the UNIX time format) in the past/future.

	John
-- 
John DuBois     spcecdt@armory.com     KC6QKZ    http://www.armory.com/~spcecdt