|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 Thanks for any |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
2007-05-31, 08:28(-07), wolffc@gmail.com:
> 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 [...] Yes, that's probably the reason. You can do (sh syntax): LC_ALL=C date +%bDecJanFebMarAprMayJunJulAugSepOctNovDec | sed 's/\(...\).*\(...\)\1.*/\2/' I'd recommend not to use csh for scripting. -- Stéphane |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
I think this is easier:
date -d "`date +%_d` day" +%b Regards. 2007-05-31, 08:28(-07), wol...@gmail.com:> 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 |
|
![]() |
| Outils de la discussion | |
|
|