From: Thomas Valerio (email_suppressed_at_lugwash.org)
Date: Wed 14-Jan-2009 07:09:45 PM EST
Now I am kind of curious when this started to work correctly. I have a
CENTOS 5.2 system that yields the correct result. However, from a RHL
7.3 & a CENTOS 4.4 system, run at approximately the time of this message:
-sh-3.00$ firstday=$(date --date "-1 month" +'%m/1/%Y')
-sh-3.00$ lastday=$(date --date "$firstday + 1 month - 1 day" +'%m/%d/%Y')
-sh-3.00$ echo $firstday $lastday
12/1/2008 01/02/2009
Does anyone else have any other non-working examples? What
distribution? Inquiring minds want to know!
-- Tom/
Steven M Campbell wrote:
> Michael Corral wrote:
>> 2009-01-13, Monsieur Robert Seward a ecrit:
>>> I would like to revise my script to be:
>>>
>>> # show off GNU date acrobatics.
>>> # Read "info date" if you don't understand this.
>>> firstDayOfMonth=$(date +%m/01/%y)
>>> lastDayOfMonth=$(date +%m/%d/%Y --date="$(date +%Y-%m-1) + 1 month - 1
>>> day")
>>>
>>> # .. and for job security (Michael's solution)
>>
>> Hehe. Hey, it's a jungle out there, you gotta do what it takes! ;)
>> Besides, for real job security it'd be in perl, where you can make
>> it look like an explosion at an ascii factory.
>>
>> By the way, we still haven't seen Steven's script. Hmm. Was he just
>> pulling a Fermat on us ("I have this wonderful two-line script..."), or
>> did we just solve a problem for him? :p
>>
>> Michael
>> --
>> *** Sent from [e-mail suppressed] *** http://www.lugwash.org
>> to unsubscribe: `echo "unsubscribe" | mail
>> [e-mail suppressed]`
>
> Very cool, I really expect it to take much longer for folks to cook
> that one up.
>
> and I did too post my script! See my post at 1:13 today where I said:
>
> I believe the bragging rights are yours. The task was for previous
> month but just subtract one month in the 'date' math but yeah, that's
> how I did it.
> Most folks aren't aware of how powerful the gnu date command is, BTW,
> my code was:
>
> firstday=$(date --date "-1 month" +'%m/1/%Y')
> lastday=$(date --date "$firstday + 1 month - 1 day" +'%m/%d/%Y')
> --
> *** Sent from [e-mail suppressed] *** http://www.lugwash.org
> to unsubscribe: `echo "unsubscribe" | mail
> [e-mail suppressed]`
-- *** Sent from [e-mail suppressed] *** http://www.lugwash.org to unsubscribe: `echo "unsubscribe" | mail [e-mail suppressed]`
This archive was generated by hypermail 2.1.5 : Sun 01-Feb-2009 01:00:01 AM EST