Ver Mensaje Individual
  #2 (permalink)  
Antiguo 17/12/2011, 02:14
dicuenca77
 
Fecha de Ingreso: agosto-2011
Mensajes: 68
Antigüedad: 12 años, 8 meses
Puntos: 11
Respuesta: Cómo averiguar el domingo de cada mes

Davape9, te pongo un código que he escrito, pero no he comprobado si funciona, pero por ahí van los tiros. A ver si te sirve. Ya me contarás si funciona:

Código:
<%
k=primerdomingo()
Response.write(k)


Function primerdomingo() 'DEVUELVE -1 SI YA HA PASADO EL PRIMER DOMINGO. EN CASO CONTRARIO DEVUELVE EL Nº DE DIAS
Dim cuantosdias, i, diactual, rfecha, pasado, k
 
 cuantosdias=UltimoDiaDeMes(month(date()), year(date()))
 i=0
 diactual=day(date())
 ' COMPROBAMOS SI YA HA PASADO EL 1º DOMINGO
 pasado=0
 do while (i<diactual)
 i=i+1
 rfecha=i&"/"&month(date())&"/"&year(date())
  if weekday(rfecha)=1 then
   pasado=-1
   i=diactual
  End if
 Loop
  ' SI NO HA PASADO EL 1º DOMINGO, CALCULAMOS EL Nº DE DIAS HASTA EL DOMINGO
 if pasado=0 then
 i=diactual-1
 k=-1
 do while (i<cuantosdias)
 i=i+1
 k=k+1
 rfecha=i&"/"&month(date())&"/"&year(date())
  if weekday(rfecha)=1 then
   pasado=k
   i=cuantosdias
  End if
 Loop 
 
 primerdomingo=pasado
 End if
 
End function

  ' FUNCION PARA CALCULAR EL Nº DE DIAS DEL MES
Function UltimoDiaDeMes(iMonth, iYear)

SDate = DateSerial(iYear, iMonth, "01")
MesSiguiente = DateAdd("m", 1, SDate)
UltimoDiaDeMes = Day(DateAdd("d", -1, MesSiguiente))
 
End Function
%>

Última edición por dicuenca77; 17/12/2011 a las 02:26