10-27-2009
No logro solucionar sacar el dia de la semana de una fecha dada.
Con este código pretendo sacar el dia de la semana dada una fecha como parametro
por ejemplo.
./dia 27 10 2009
El resultado saliera:
Martes
El problema es que cuando llego casi al final el lunes etsa representado por un 0. el martes por 1.. y quiero hacer un bucle if para sustituir el 0 por Lunes
de este modo
if [$dow -eq 0] then
echo -"Lunes"
else
fi
Pero todo el rato me da error
y no se porque.
¿Alguien me podria ayudar?
Gracias
#!/bin/sh
# ja fe ma ap ma ju ju ag se oc no de
set -A lasts 0 31 28 31 30 31 30 31 31 30 31 30 31
dia=$1
mes=$2
anyo=$3
#
# Get Day of Week of Jan 1
dow1=$(cal 1 $anyo | sed -n '3s/. //gp')
((dow1=7-dow1))
#
# Es año Bisiesto?
leap=0
if ((!(anyo%100))); then
((!(anyo%400))) && leap=1
else
((!(anyo%4))) && leap=1
fi
#
# Establecer numero de dias de Febrero
lasts[2]=28
((leap)) && lasts[2]=29
#
# calculate day of year
i=0
previous=0
while ((i < mes)) ; do
((previous=previous+lasts[i]))
((i=i+1))
done
((doy=previous+dia))
#
# Calculate day of week
((dow = (doy+dow1-1)%7 ))
#echo dow = $dow
echo diadelasemana=$dow
if [$dow -eq 0] then
echo -"Lunes"
else
echo "..ya seguiria con cada numero"
fi
exit 0
---------- Post updated at 08:17 AM ---------- Previous update was at 08:10 AM ----------
Sorry i didn't realize that I had to write in English
My problem is that i want to calculate the day of the week, i want to change result given as a number for the day.
I mean, the program now do that if the day is Monday is represented by 0, Tuesday by 1.. but i want the word "Monday" as a result. I thought in a bucle if but there is always a mistake and i dont know why.
Thank you
5 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi, I wonder if someone can help me with what is probably a very easy question. :)
I'm relatively new to UNIX and have recently been trying to get into it more since I bought a new Mac. I'm trying to run the dada engine (to generate random text based on rules) but I can't seem to get it to work.... (2 Replies)
Discussion started by: cptj
2 Replies
2. UNIX Desktop Questions & Answers
Hola, alguien me puede ayudar enviandome los comandos para cpnsultar las HBA que estan asignadas y que ve un servidor con SO tru Unix64
Gracias (1 Reply)
Discussion started by: darru
1 Replies
3. Shell Programming and Scripting
Hola, no se casi nada de linux pero tengo que hacer un tp para la facultad, y uno de los puntos me pide que muestre en pantalla la fecha de creacion , modificacion y ultimo acceso de un fichero pasado por parametro a un script.:confused:
Alguien me ayuda!? gracias. (1 Reply)
Discussion started by: palitodlselva
1 Replies
4. Shell Programming and Scripting
Tengo un fichero con este formato:
A1
A2
A3
A4
B1
B2
B3
B4
.
.
.
.
y lo quiero convertir en esto:
A1 A2 A3 A4
B1 B2 B3 B4
.. .. ..... . . .. (1 Reply)
Discussion started by: manudbc
1 Replies
5. HP-UX
Hola a todos, me gustaría saber cómo chequear si estas LUN´s
objecthexuid .........................: 6005-08b4-0001-529c-0005-6000-45d6-0000
objecthexuid .........................: 6005-08b4-0001-529c-0005-6000-45d9-0000
objecthexuid .........................:... (1 Reply)
Discussion started by: aav1307
1 Replies
LEARN ABOUT MOJAVE
datetime::leapsecond5.18
DateTime::LeapSecond(3) User Contributed Perl Documentation DateTime::LeapSecond(3)
NAME
DateTime::LeapSecond - leap seconds table and utilities
VERSION
version 1.06
SYNOPSIS
use DateTime;
use DateTime::LeapSecond;
print "Leap seconds between years 1990 and 2000 are ";
print DateTime::Leapsecond::leap_seconds( $utc_rd_2000 ) -
DateTime::Leapsecond::leap_seconds( $utc_rd_1990 );
DESCRIPTION
This module is used to calculate leap seconds for a given Rata Die day. It is used when DateTime.pm cannot compile the XS version of this
code.
This library is known to be accurate for dates until December 2009.
There are no leap seconds before 1972, because that's the year this system was implemented.
o leap_seconds( $rd )
Returns the number of accumulated leap seconds for a given day, in the range 0 .. 22.
o extra_seconds( $rd )
Returns the number of leap seconds for a given day, in the range -2 .. 2.
o day_length( $rd )
Returns the number of seconds for a given day, in the range 86398 .. 86402.
SEE ALSO
<http://hpiers.obspm.fr/eop-pc/earthor/utc/leapsecond.html>
http://datetime.perl.org
AUTHOR
Dave Rolsky <autarch@urth.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by Dave Rolsky.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
perl v5.18.2 2017-10-06 DateTime::LeapSecond(3)