SUMMARY: 'date' for tomorrow

From: Enrique Vadillo (vadillo@rcp.net.pe)
Date: Tue Apr 20 1999 - 15:46:47 CDT


Hi,

I was overwhelmed by so many replies, everybody had a different 'solution'
going from changing TZ (did not work) to perl, some other sent URLs
for mktime explanations and someone sent me C code to compile :)

My original question was:
------------------------------------------------------------------------
I am writing a shell script that requires not TODAY's but TOMORROW's
date, can 'date' somehow do that?
------------------------------------------------------------------------

Best responses were sent by Steven Sakata <steven@hawaii.edu>:

------------------------------------------------------------------------
I couldn't find anyway of getting the "date" command to do what you're asking,
but just in case you have perl, you can get tommorrow's date with a few lines:
#!/usr/local/bin/perl
@tm = localtime(time() + (24*60*60));
printf ("%d%02d%02d\n", $tm[5]+1900, $tm[4]+1, $tm[3]);
------------------------------------------------------------------------

A good (but rather long) one was sent by Michael Sullivan <mps@discomsys.com>:

---------- begin ---------
#!/bin/sh

leap_year(){
        year=$1
        # First check for century leap year
        if [ `expr ${year} % 400` -eq 0 ]
        then
                echo 1
        elif [ `expr ${year} % 4` -eq 0 ]
        then
                echo 1
        else
                echo 0
        fi
}

get_year(){
        echo $1
}

get_month(){
        echo $2
}

get_day(){
        echo $3
}

if [ $# -eq 3 ]
then
        year=$1
        month=$2
        day=$3
elif [ $# -eq 0 ]
then
        today=`date '+%Y %m %d'`
        year=`get_year ${today}`
        month=`get_month ${today}`
        day=`get_day ${today}`
else
        echo "Usage: $0 [YYYY MM DD]"
        exit
fi

days_in_month="31 28 31 30 31 30 31 31 30 31 30 31"
i=1
for num_days in ${days_in_month}
do
        if [ ${i} -eq ${month} ]
        then
                break
        fi
        i=`expr ${i} + 1`
done

if [ ${month} -eq 2 ]
then
        if [ `leap_year ${year}` -eq 1 ]
        then
                num_days=`expr ${num_days} + 1`
        fi
fi

echo "Number of days: ${num_days}"

day=`expr ${day} + 1`
if [ ${day} -gt ${num_days} ]
then
        day=1
        month=`expr ${month} + 1`
        if [ ${month} -gt 12 ]
        then
                month=1
                year=`expr ${year} + 1`
        fi
fi

echo "${year} ${month} ${day}"
--- end ----

More responses were sent by the following people:

timothy.p.peterman@lmco.com (Timothy P. Peterman)
bern@TI.Uni-Trier.DE (Jochen Bern)
gfranczyk@carbomedics.com (Franczyk, Gary)
mark_studebaker@reyrey.com (Studebaker, Mark R)
rangern@CIRANO.UMontreal.CA (Normand Ranger)
Baranyai.Pal@Synergon.Hu (Baranyai Pal)
anders@hmi.de (Thomas Anders)
MTindall@Derwent.co.uk (Tindall, Mark)
MARTENSD@health.qld.gov.au (Dennis Martens)
vogelke@c17mis.region2.wpafb.af.mil
squaint@provide.net (Sean Quaint)
Jonathan.Small@chase.com
negativl@netcom.com (Raymond Wong)
sweh@mpn.com (Stephen Harris)
woolsey@jlw.com (Jeff Woolsey)
bevanb@ee.uwa.edu.au (Bevan Broun)
mwang@tech.cicg.ml.com (Michael Wang)
rmf@unixbox.lookhere.com (Roger Fujii)
eric@outlook.net (Eric D. Pancer)
steven@hawaii.edu (Steven Sakata)

Enrique-

-- 
----------------------------------------------
 RCP - Internet Peru      Tel: +51 1 422-4848 
 Dpto de Operaciones      Fax: +51 1 421-8086
----------------------------------------------



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:13:18 CDT