Subject: Re: date feature request
To: Lubomir Sedlacik <salo@xtrmntr.org>
From: matthew sporleder <msporleder@gmail.com>
List: netbsd-users
Date: 11/14/2006 09:59:35
On 11/14/06, Lubomir Sedlacik <salo@xtrmntr.org> wrote:
> On Tue, Nov 14, 2006 at 12:12:23AM -0600, John Darrow wrote:
> > The main question is what option letter to use?  -R (like suggested
> > above)?  -N (a common "don't actually do it, just show me what would
> > happen" option letter)?  Something else?  Is there any prior art for
> > this?  Does POSIX or anything else have anything to say?  What color
> > should we paint the bike shed? ;-)
>
> POSIX says nothing about it:
>
>  http://www.opengroup.org/onlinepubs/009695399/utilities/date.html
>
> both FreeBSD and OpenBSD provide this functionality with the -j option:
>
>  http://www.FreeBSD.org/cgi/man.cgi?query=date&sektion=1&manpath=FreeBSD+7.0-current
>  http://www.OpenBSD.org/cgi-bin/man.cgi?query=date&sektion=1&manpath=OpenBSD+Current
>


You can also do most of this stuff portably with awk.
Here's an easy example of yesterday: (tested on netbsd and solaris)

echo|awk 'BEGIN { d = systime() - 86400; } END { print strftime("%c", d) }'

_Matt

From AWK(1)
   Time Functions
     This awk provides the following two functions for obtaining time stamps
     and formatting them:

     systime()
             Returns the value of time in seconds since the start of Unix
             Epoch (Midnight, January 1, 1970, Coordinated Universal Time).
             See also time(3).

     strftime([format [, timestamp]])
             Formats the time timestamp according to the string format.
             timestamp should be in same form as value returned by systime().
             If timestamp is missing, current time is used. If format is miss-
             ing, a default format equivalent to the output of date(1) would
             be used. See the specification of ANSI C strftime(3) for the for-
             mat conversions which are supported.