Função VBScript DatePart
❮ Referência completa do VBScriptA função DatePart retorna a parte especificada de uma determinada data.
Sintaxe
DatePart(interval,date[,firstdayofweek[,firstweekofyear]])
Parameter | Description |
---|---|
interval | Required. The interval of time to return. Can take the following values:
|
date | Required. Date expression to evaluate |
firstdayofweek | Optional. Specifies the day of the week. Can take the following values:
|
firstweekofyear | Optional. Specifies the first week of the year. Can take the following values:
|
Exemplos
Exemplo 1
Obter o mês de uma data:
<%
d=CDate("2010-02-16")
response.write(DatePart("m",d))
%>
A saída do código acima será:
2
Exemplo 2
Obtenha o mês em que estamos:
<%
response.write(DatePart("m",Now()))
%>
A saída do código acima será:
1
Exemplo 3
Obter a hora:
<%
response.write(DatePart("h",Now())
%>
A saída do código acima será:
13
❮ Referência completa do VBScript