PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > date function current month and last month the same
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

date function current month and last month the same

Réponse
 
LinkBack Outils de la discussion
Vieux 31/05/2007, 16h28   #1
wolffc@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut date function current month and last month the same

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

  Réponse avec citation
Vieux 31/05/2007, 16h48   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: date function current month and last month the same

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
  Réponse avec citation
Vieux 31/05/2007, 16h54   #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
Vieux 31/05/2007, 19h48   #4
Jose H.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: date function current month and last month the same

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


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h28.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09932 seconds with 12 queries