Funzione VBScript DatePart

❮ Riferimento completo di VBScript

La funzione DatePart restituisce la parte specificata di una data data.

Sintassi

DatePart(interval,date[,firstdayofweek[,firstweekofyear]])
Parameter Description
interval Required. The interval of time to return.

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
date Required. Date expression to evaluate
firstdayofweek Optional. Specifies the day of the week.

Can take the following values:

  • 0 = vbUseSystemDayOfWeek - Use National Language Support (NLS) API setting
  • 1 = vbSunday - Sunday (default)
  • 2 = vbMonday - Monday
  • 3 = vbTuesday - Tuesday
  • 4 = vbWednesday - Wednesday
  • 5 = vbThursday - Thursday
  • 6 = vbFriday - Friday
  • 7 = vbSaturday - Saturday
firstweekofyear Optional. Specifies the first week of the year.

Can take the following values:

  • 0 = vbUseSystem - Use National Language Support (NLS) API setting
  • 1 = vbFirstJan1 - Start with the week in which January 1 occurs (default)
  • 2 = vbFirstFourDays - Start with the week that has at least four days in the new year
  • 3 = vbFirstFullWeek - Start with the first full week of the new year

Esempi

Esempio 1

Ottieni il mese da una data:

<%

d=CDate("2010-02-16")
response.write(DatePart("m",d))

%>

L'output del codice sopra sarà:

2

Esempio 2

Ottieni il mese in cui siamo:

<%

response.write(DatePart("m",Now()))

%>

L'output del codice sopra sarà:

1

Esempio 3

Ottieni l'ora:

<%

response.write(DatePart("h",Now())

%>

L'output del codice sopra sarà:

13

❮ Riferimento completo di VBScript