Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/10/2013, 16:54
Toninito
 
Fecha de Ingreso: abril-2010
Mensajes: 40
Antigüedad: 14 años
Puntos: 0
Número se semana con Javascript

Buen dia

Tengo el siguiente codigo y lo que necesito es que me de el número de semana del año por Ej: hoy es 1-Oct-2013 y el número de semana es la 40

Cuando le de click al textbox me ponga el número de semana actual

Espero y puedan ayudarme de antemano muchas gracias

Saludos.

Código HTML:
<script>
function getWeekNr()
{
        var today = new Date();
        Year = takeYear(today);
        Month = today.getMonth();
        Day = today.getDate();
        now = Date.UTC(Year,Month,Day+1,0,0,0);
        var Firstday = new Date();
        Firstday.setYear(Year);
        Firstday.setMonth(0);
        Firstday.setDate(1);
        then = Date.UTC(Year,0,1,0,0,0);
        var Compensation = Firstday.getDay();
        if (Compensation > 3) Compensation -= 4;
        else Compensation += 3;
        NumberOfWeek =  Math.round((((now-then)/86400000)+Compensation)/7);
        return NumberOfWeek;
}


function takeYear(theDate)
{
        x = theDate.getYear();
        var y = x % 100;
        y += (y < 38) ? 2000 : 1900;
        return y;
}
</script>

<form name="form1" method="post" action="">
  <input type="text" name="textfield" id="textfield" onClick="getWeekNr()">
</form>