Afficher un message
Vieux 31/05/2007, 17h54   #3
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: date function current month and last month the same

On 31 May 2007 08:28:26 -0700, wolffc@gmail.com
<wolffc@gmail.com> wrote:
>
>
> I have a process the uses the date function to get the last month and
> the current month. Here are the functions
>
> set x = `date -d "-1 month" +%b`
> set y = `date -d "0 month" +%b`
>
> For some reason x and y are both May. Does this have something to do
> with May being 31 days? This had been working all of April and all of
> May. I am using csh
>

From `info date`:
The fuzz in units can cause problems with relative items. For
example, `2003-07-31 -1 month' might evaluate to 2003-07-01, because
2003-06-31 is an invalid date. To determine the previous month more
reliably, you can ask for the month before the 15th of the current
month. For example:

$ date -R
Thu, 31 Jul 2003 13:02:39 -0700
$ date --date='-1 month' +'Last month was %B?'
Last month was July?
$ date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!'
Last month was June!


--
Most people prefer certainty to truth.
  Réponse avec citation
 
Page generated in 0,04891 seconds with 9 queries