avoir la date à partir de nb bjour

avoir la date à partir de nb bjour - Shell/Batch - Programmation

Marsh Posté le 03-12-2005 à 13:34:36    

Bonjour,
est ce qu'il y a un moyen en script shell d'avoir la date à partir du nombre de jour de l'année.
c.a.d :

Code :
  1. nb jour année : 1   ----> 01/01/2005
  2. nb jour année : 3  -----> 03/01/2005


Merci

Reply

Marsh Posté le 03-12-2005 à 13:34:36   

Reply

Marsh Posté le 04-12-2005 à 00:52:24    

"Script shell" ? Unix ? Windows ?
 
En VBS pour Windows :

date_debut_annee = DateValue("01/01" )
 
quantieme = 1
la_date = DateAdd("d", date_debut_annee, quantieme - 1)
Wscript.Echo la_date
 
quantieme = 3
la_date = DateAdd("d", date_debut_annee, quantieme - 1)
Wscript.Echo la_date
 
quantieme = 360
la_date = DateAdd("d", date_debut_annee, quantieme - 1)
Wscript.Echo la_date

Reply

Marsh Posté le 04-12-2005 à 10:26:53    

Citation :


"Script shell" ? Unix ? Windows ?  


 
Unix

Reply

Marsh Posté le 04-12-2005 à 12:54:50    

Unix ? Quelle version d'Unix ? (attention, ensuite je demanderai quel shell  :) )
 
Essayer :

# Calcul 1er janvier plus n jours (non testé)
j0=1; m0=1; a0=`date +"%Y"`
n=1;
#n=3
#n=360
j=$(expr $j0 + n)
m=$m0
while [ 1 ]
do
   case $m in
         1|3|5|7|8|10|12) jj="31" ;;
                 2) if [ `cal 02 $a0|grep -c "29"` = 1 ]
                               then jj="29"
                               else jj="28"
                            fi
                            ;;
                         *) jj="30" ;;
   esac
   if [ $jj > $j ]
      then break
   fi
   j=$(expr $j - $jj)
   m=$(expr $m + 1)
done
if [ "$(expr length $j)" != 2 ]
   then jj="0$j"
fi
if [ "$(expr length $m)" != 2 ]
   then mm="0$m"
fi
echo "$jj/$mm/$a0"

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed