VBScript DateDiffFunción
Referencia completa de VBScript
La función DateDiff devuelve el número de intervalos de tiempo entre dos fechas.
Sintaxis
DateDiff(interval,date1,date2[,firstdayofweek[,firstweekofyear]])
| Parámetros | Descripción |
|---|---|
| interval | Obligatorio. Unidad de intervalo de tiempo entre date1 y date2. Puede tomar los siguientes valores:
|
| date1,date2 | Obligatorio. Expresiones de fecha. Las dos fechas que se usan en el cálculo. |
| firstdayofweek | Opcional. Especifica el día de la semana. Puede tomar los siguientes valores:
|
| firstweekofyear | Opcional. Especifica la primera semana del año. Puede tomar los siguientes valores:
|
Ejemplos
Ejemplo 1
La diferencia entre el 31 de enero de 2009 y el 31 de enero de 2010:
<script type="text/vbscript">
fromDate="31-Jan-09 00:00:00"
toDate="31-Jan-10 23:59:00"
document.write(DateDiff("yyyy",fromDate,toDate) & "<br />")
document.write(DateDiff("q",fromDate,toDate) & "<br />")
document.write(DateDiff("m",fromDate,toDate) & "<br />")
document.write(DateDiff("y",fromDate,toDate) & "<br />")
document.write(DateDiff("d",fromDate,toDate) & "<br />")
document.write(DateDiff("w",fromDate,toDate) & "<br />")
document.write(DateDiff("ww",fromDate,toDate) & "<br />")
document.write(DateDiff("h",fromDate,toDate) & "<br />")
document.write(DateDiff("n",fromDate,toDate) & "<br />")
document.write(DateDiff("s",fromDate,toDate) & "<br />")
</script>
fromDate="31-Jan-09 00:00:00"
toDate="31-Jan-10 23:59:00"
document.write(DateDiff("yyyy",fromDate,toDate) & "<br />")
document.write(DateDiff("q",fromDate,toDate) & "<br />")
document.write(DateDiff("m",fromDate,toDate) & "<br />")
document.write(DateDiff("y",fromDate,toDate) & "<br />")
document.write(DateDiff("d",fromDate,toDate) & "<br />")
document.write(DateDiff("w",fromDate,toDate) & "<br />")
document.write(DateDiff("ww",fromDate,toDate) & "<br />")
document.write(DateDiff("h",fromDate,toDate) & "<br />")
document.write(DateDiff("n",fromDate,toDate) & "<br />")
document.write(DateDiff("s",fromDate,toDate) & "<br />")
</script>
El resultado del ejemplo anterior es:
1
4
12
365
365
52
53
8783
527039
31622340
4
12
365
365
52
53
8783
527039
31622340
Pruébalo »
Ejemplo 2
Cuántas semanas hay entre el 31 de diciembre de 2009 y el 31 de diciembre de 2012 (comenzando el lunes):
<script type="text/vbscript">
fromDate=CDate("2009/12/31")
toDate=CDate("2012/12/31")
document.write(DateDiff("w",fromDate,toDate,vbMonday))
</script>
fromDate=CDate("2009/12/31")
toDate=CDate("2012/12/31")
document.write(DateDiff("w",fromDate,toDate,vbMonday))
</script>
El resultado del ejemplo anterior es:
156
Pruébalo »
Referencia completa de VBScript Otras extensiones