|
Home > Archive > Unix Shell > May 2007 > date function current month and last month the same
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
date function current month and last month the same
|
|
| wolffc@gmail.com 2007-05-31, 1:21 pm |
| 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 help
| |
| Stephane CHAZELAS 2007-05-31, 1:21 pm |
| 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 +%bDecJanFebMarAprMayJunJulAugSepOctNovD
ec |
sed 's/\(...\).*\(...\)\1.*/\2/'
I'd recommend not to use csh for scripting.
--
Stéphane
| |
| Bill Marcum 2007-05-31, 1:21 pm |
| 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.
| |
| Jose H. 2007-05-31, 7:24 pm |
| 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
|
|
|
|
|