Funzione di aggiunta della data di VBScript

❮ Riferimento completo di VBScript

La funzione DateAdd restituisce una data a cui è stato aggiunto un intervallo di tempo specificato.

Sintassi

DateAdd(interval,number,date)
Parameter Description
interval Required. The interval you want to add

Can take the following values:

  • yyyy - Year
  • q - Quarter
  • m - Month
  • y - Day of year
  • d - Day
  • w - Weekday
  • ww - Week of year
  • h - Hour
  • n - Minute
  • s - Second
number Required. The number of interval you want to add. Can either be positive, for dates in the future, or negative, for dates in the past
date Required. Variant or literal representing the date to which interval is added

Esempi

Esempio 1

Come utilizzare i parametri:

<%

response.write(DateAdd("yyyy",1,"31-Jan-10") & "<br />")
response.write(DateAdd("q",1,"31-Jan-10") & "<br />")
response.write(DateAdd("m",1,"31-Jan-10") & "<br />")
response.write(DateAdd("y",1,"31-Jan-10") & "<br />")
response.write(DateAdd("d",1,"31-Jan-10") & "<br />")
response.write(DateAdd("w",1,"31-Jan-10") & "<br />")
response.write(DateAdd("ww",1,"31-Jan-10") & "<br />")
response.write(DateAdd("h",1,"31-Jan-10 08:50:00") & "<br />")
response.write(DateAdd("n",1,"31-Jan-10 08:50:00") & "<br />")
response.write(DateAdd("s",1,"31-Jan-10 08:50:00") & "<br />")

%>

L'output del codice sopra sarà:

1/31/2011
4/30/2010
2/28/2010
2/1/2010
2/1/2010
2/1/2010
2/7/2010
1/31/2010 9:50:00 AM
1/31/2010 8:51:00 AM
1/31/2010 8:50:01 AM

Esempio 2

Sottrai un mese dal 31 gennaio 2010

<%

response.write(DateAdd("m",-1,"31-Jan-10"))

%>

L'output del codice sopra sarà:

12/31/2009

Esempio 3

Aggiungi un giorno da adesso:

<%

response.write(DateAdd("d",1,Now()))

%>

L'output del codice sopra sarà:

1/30/2022 4:00:51 PM

❮ Riferimento completo di VBScript