*BSD News Article 34886


Return to BSD News archive

Xref: sserve comp.unix.bsd:14689 comp.unix.misc:13624 comp.unix.programmer:19494 comp.unix.questions:54094
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!msuinfo!agate!howland.reston.ans.net!EU.net!sunic!trane.uninett.no!nac.no!ifi.uio.no!harald
From: harald@ifi.uio.no (Harald Eikrem)
Newsgroups: comp.unix.bsd,comp.unix.misc,comp.unix.programmer,comp.unix.questions
Subject: Re: Q:  How can I get yesterday's date?
Date: 24 Aug 1994 18:40:49 +0200
Organization: The Overseas Mission for the Venerally Defeated
Lines: 34
Message-ID: <33ft6h$ecf@trantjern.ifi.uio.no>
References: <Pine.3.89.9408160216.A15886-0100000@worf.uwsp.edu>
	<32q00b$9vn@daphne.ecmwf.co.uk> <32qdqm$bnv@access1.digex.net>
NNTP-Posting-Host: trantjern.ifi.uio.no
In-Reply-To: saalwaec@access1.digex.net's message of 16 Aug 1994 09:09:42 -0400

saalwaec@access1.digex.net (John W. Saalwaechter) suggested:
! % date -r `perl -e 'print time - 24*60*60'`
! Mon Aug 15 08:56:15 EDT 1994
! %
!
! Combine the '-r' option to date with perl's 'time' capability to get yesterday's date.
! For your specific question (using the Bourne shell):
!
! $ yestertime=`perl -e 'print time - 24*60*60'`
! $ yy=`date -r $yestertime +%y`
! $ mm=`date -r $yestertime +%m`
! $ dd=`date -r $yestertime +%d`
! $ fn="GS$yy$mm$dd.LOG"


Nah, have it all happen in in perl:

% date
Wed Aug 24 18:33:37 MET DST 1994

% perl -e '@_=(localtime(time-86400))[5,4,3];++$_[1];printf"%02d%02d%02d\n",@_'
940823

% perl -v

This is perl, version 4.0

$RCSfile: perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $
Patch level: 36

....


  ~~h