Yesterdays date in a shell script

Yesterdays date in a shell script

Post by Neil Pearc » Thu, 01 May 1997 04:00:00



What's wrong with....

    #!/bin/sh
    TZ=GMT+24
    export TZ
    date

        Neil

 
 
 

Yesterdays date in a shell script

Post by Jon LaBad » Sun, 04 May 1997 04:00:00


|> What's wrong with....
|>
|>     #!/bin/sh
|>     TZ=GMT+24
|>     export TZ
|>     date

The topic of date manipulation comes up so often that a general
solution is needed.

I am running an old SVR4.0 version of unix, Dell's Issue 2.2.
They supplied several "then current" software packages, including
cnews.  In the cnews package is a program called "getdate".  This
program has a lex/yacc parser that accepts arguments like:

  getdate "yesterday"
  getdate "now +5 hours"
  getdate "next month"

The output of this "getdate" program is UNIX time, i.e. seconds.
It has to be fed to a 'ctime' type program.  For example:

  ctime `getdate yesterday`

That ctime program could output any part of the date.

If that program could be made available to all unicies,
I think that the problem of date calculation would be
eliminated.

Current cnews distributions have a different getdate program
that is optimized for cnews needs.

jon
--


 4455 Province Line Road        (609) 252-0159
 Princeton, NJ  08540-4322      (609) 683-7220 (fax)

 
 
 

Yesterdays date in a shell script

Post by Bob Van Der Po » Sun, 04 May 1997 04:00:00


I need to find out the name of last month...again, not all that trivail. I finally
hacked shell script together to do thsi, but it is ugly! A neat command to do this
kind of stuff would be very nice. Hmmm, maybe I should start hacking...


: |> What's wrong with....
: |>
: |>     #!/bin/sh
: |>     TZ=GMT+24
: |>     export TZ
: |>     date

: The topic of date manipulation comes up so often that a general
: solution is needed.

: I am running an old SVR4.0 version of unix, Dell's Issue 2.2.
: They supplied several "then current" software packages, including
: cnews.  In the cnews package is a program called "getdate".  This
: program has a lex/yacc parser that accepts arguments like:

:   getdate "yesterday"
:   getdate "now +5 hours"
:   getdate "next month"

: The output of this "getdate" program is UNIX time, i.e. seconds.
: It has to be fed to a 'ctime' type program.  For example:

:   ctime `getdate yesterday`

: That ctime program could output any part of the date.

: If that program could be made available to all unicies,
: I think that the problem of date calculation would be
: eliminated.

: Current cnews distributions have a different getdate program
: that is optimized for cnews needs.

: jon
: --


:  4455 Province Line Road        (609) 252-0159
:  Princeton, NJ  08540-4322      (609) 683-7220 (fax)

--
   __
  /  )      /         Bob van der Poel

/___/_(_) /_)         http://www2.awinc.com/users/bvdpoel

 
 
 

Yesterdays date in a shell script

Post by Michael Fu » Sun, 04 May 1997 04:00:00



> The topic of date manipulation comes up so often that a general
> solution is needed.

Perl with one of the Date:: modules (e.g., Date::Manip) works great
for date calculations.

--
Michael Fuhr
http://www.dimensional.com/~mfuhr/

 
 
 

Yesterdays date in a shell script

Post by Michael Fu » Mon, 05 May 1997 04:00:00



Quote:> I need to find out the name of last month...again, not all that trivail. I finally
> hacked shell script together to do thsi, but it is ugly! A neat command to do this
> kind of stuff would be very nice. Hmmm, maybe I should start hacking...

Trivial with Perl:

    #!/usr/local/bin/perl -w
    use Date::Manip;
    $date = &DateCalc("today", "-1 month");
    print &UnixDate($date, "%B\n");

--
Michael Fuhr
http://www.dimensional.com/~mfuhr/

 
 
 

Yesterdays date in a shell script

Post by Brian S Hil » Wed, 07 May 1997 04:00:00



: I need to find out the name of last month...again, not all that
: trivail. I finally hacked shell script together to do thsi, but it is
: ugly! A neat command to do this kind of stuff would be very nice.
: Hmmm, maybe I should start hacking...

What is so hard about it?

set -A month X Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
print -r ${month[(mm=$(date +%m) )==1?12:mm-1]}

Oh yah, I guess the above is ksh93. In ksh88, the above would be written:

set -A month X Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
(((mm=$(date +%m) )==1)) && mm=12
print -r ${month[mm-1]}

-Brian
--
   ,---.     ,---.     ,---.     ,---.     ,---.     ,---.     ,---.  
  /  _  \   /  _  \   /  _  \   /  _  \   /  _  \   /  _  \   /  _  \  

__,'   `.___,'   `.___,'   `.___,'   `.___,'   `.___,'   `.___,'   `.__

 
 
 

Yesterdays date in a shell script

Post by Christian Fruehlin » Wed, 14 May 1997 04:00:00


under Linux I just enter:

   date -d '1 month ago' +%B

and I get

   April

--
Christian Frhling