Summary :incrementing a date

From: Chua Koon Teck <koonteck_at_singnet.com.sg>
Date: Mon, 25 Mar 1996 11:00:00 +0800 (SST)

Below is a summary of the response that I have got on the above topic :

It seems that gnudate is a right application for incrementing a date. You
can get it from ftp.cs.waikato.ac.nz/pub/packages/gnu/sh_utils-1.12.tar.gz.


My origin question is :

How can I add to a date field to increment it by days in korn shell ?
This is not just simply adding into the day field of the date because in a
date field, there is month and year.

For example, if date = 31/3/96, if I will to add one day to it, it should
give me 1/4/96, and not 32/3/96.

===============================================================
>From bennett_at_hpel.cees.eduMon Mar 25 10:55:59 1996
Date: Sat, 23 Mar 1996 01:32:05 -0500 (EST)
From: Eric Bennett <bennett_at_hpel.cees.edu>
To: Chua Koon Teck <koonteck_at_singnet.com.sg>
Subject: Re: incrementing a date

> For example, if date = 31/3/96, if I will to add one day to it, it should
> give me 1/4/96, and not 32/3/96.

If you want an offset from now, you can use this timezone hack. It's
timezone specific though, so don't use it for anything you will
distribute.

My timezone is EST+5EDT. If I want yesterday I add 24 to my timezone
offset and if I want tomorrow I subtract:

# Kill logs from two days ago
killdate=`TZ=EST+53EDT date +%Y%m%d`


If your time zone is SST-8SDT (just guessing) then you could print
tomorrow's date with:

TZ=SST-32SDT date +%d/%m/%y


I don't know how this behaves for daylight savings time switches.

        Eric B.
=====================================================================
>From SXKAC_at_orca.alaska.eduMon Mar 25 10:56:09 1996
Date: Sat, 23 Mar 1996 07:47:50 -0900
From: Kurt Carlson <SXKAC_at_orca.alaska.edu>
To: koonteck_at_SINGNET.COM.SG
Subject: Re: incrementing a date

> How can I add to a date field to increment it by days in korn shell ?
> This is not just simply adding into the day field of the date because in a
> date field, there is month and year.

The date command can edit a date in a variety of formats but I
found no convenient means to increment|decrement short of a function.
I wrote a quick C program to increment or decrement and to output
the date in several format I've encountered in Unix. As there is no
consistant date format for unix commands I figured I'd encounter others
and have to add them later. Ours behaves as follows:

sxkac_at_nugget> date=`ua_date +1 -uerf`
sxkac_at_nugget> echo $date
24-Mar-1996,07:32:11
sxkac_at_nugget> ua_date ?
ua_date Convert date and time formats

  date Argument date to convert, defaults to now Default:960323.073219
        Formats yymmdd[.hh[mm[ss]]]
                        yyjjj.hhmmss (julian date)
                        +d.hhmmss (delta plus)
                        -d.hhmmss (delta minus)
                (time is optional in all formats)

  -normal Flag(2) output normal (default) Default:False
  -reset Flag(2) output for unix date setting Default:False
  -uerf Flag(2) output for uerf display Default:False
  -hsz40 Flag(2) output for hsz40 set this time= Default:False
  -scheduler Flag(2) output for scheduler absolute format Default:False
  -delta Flag(2) output for scheduler delta format Default:False
  -all Flag(2) output all formats above Default:False

If you hear of a better way please summarize. If you want the
code I use let me know and I'll send it. Sorry, but it isn't
internationalized for when month is output as alpha not numeric
and the specific format you used in your example (dd/mm/yy) isn't
in there (but would be easy enough to add).

Regards, Kurt Carlson, U of Alaska
============================================================
>From mike_at_lucy.cs.waikato.ac.nzMon Mar 25 10:56:18 1996
Date: Sun, 24 Mar 1996 12:03:11 +1200
From: "Mahendra Vallabh (Mike)" <mike_at_lucy.cs.waikato.ac.nz>
To: Chua Koon Teck <koonteck_at_singnet.com.sg>
Subject: Re: incrementing a date

Hi; you say:
|Hi
|
|Pls pardon me if my question is not directly relevant to OSF1.
|
|How can I add to a date field to increment it by days in korn shell ?
|This is not just simply adding into the day field of the date because in a
|date field, there is month and year.
|
|For example, if date = 31/3/96, if I will to add one day to it, it should
|give me 1/4/96, and not 32/3/96.
|
|Any help will be greatly appreciated.
|
|Thank you.
|
|Have a nice day.
|
|
|
|Regards
|____________________________________________________________________________
|Chua Koon Teck
|Singapore Telecom
|Comcentre
|SingNet
|email=koonteck_at_singnet.com.sg
|URL="http://www.singnet.com.sg/~koonteck"
|____________________________________________________________________________

Chua Koon Teck,

Install gnudate. It is better than your average date program and you can
ask it questions like.

   date --date yesterday OR
   date --date '2 days ago'

 /------------------------------------------------------------------------\
 | Mahendra Vallabh (Mike) Phone: +64 (7) 838 4549 |
 | UNIX Administration Fax: +64 (7) 838 4155 |
 | Technical Support Group Email: mike_at_cs.waikato.ac.nz |
 | School of Computing |
 | and Mathematical Sciences University of Waikato, NZ |
 | |
 | Out the 10Base-T, through the router, down the T1, over the leased |
 | line, off the bridge, past the firewall...nothing but Net |
 \------------------------------------------------------------------------/
 
"Imagination is more important than knowledge. Knowledge is limited.
 Imagination encircles the world."

Albert Einstein
Received on Mon Mar 25 1996 - 04:28:02 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:46 NZDT