From: kevin lyda (kevin at domain suberic.net)
Date: Mon 13 Aug 2001 - 18:03:23 IST
On Mon, Aug 13, 2001 at 04:14:59PM +0100, Will Mernagh wrote:
> DAYa=`date | awk '{print $3}'`
> DAYb=`expr $DAYa - 1`
> MONTH=`date '+%m'`
> YEAR=`date | awk '{print $6}'`
> DATEa=$DAYa'-'$MONTH'-'$YEAR
> DATEb=$DAYb'-'$MONTH'-'$YEAR
>
> How can I change the month from 08 to 8. I was thinking of using ${MONTH/0/}
please. stop. using. awk. it's not often that i say this, but you
don't need awk here. go read the date man page and delete every line
except the DATEa= and DATEb= ones. and for them, replace them with
something like:
DATEa=`date "%x-%x-%x"`
DATEb=`date -d yesterday "%x-%x-%x"`
the various %x's are to be discovered by reading the man page. note the
-d yesterday - your code would fail on the first of the month.
finally if there's *any* chance your code will run at midnight, then do
something like this:
NOW=`date "%z/%z/%z"` # NOW should equal mm/dd/yyyy
DATEa=`date -d "$NOW" "%x-%x-%x"`
DATEb=`date -d "$NOW - 1 day ago" "%x-%x-%x"`
%z/%z/%z above should be replaced by some incantation that yields the
american date format: mm/dd/yyyy
kevin
-- kevin at domain suberic.net simple four line sigs - fork()'ed on 37058400 bandwidth friendly; nice to do. meatspace place: home some admins clueless. http://suberic.net/~kevin --netiquette haiku 2001
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:11:36 GMT