Função DateDiff

Returns the number of date or time intervals between two given date values.

Sintaxe:


DateDiff (interval As String, date1 As Date, date2 As Date [, firstDayOfWeek As Integer [, firstWeekOfYear As Integer]]) As Double

Valor de retorno:

Um número.

Parâmetros:

interval - A string expression from the following table, specifying the date or time interval.

interval (string value)

Explicação

yyyy

Ano

q

Trimestre

m

Mês

y

Dia do ano

w

Dia da semana

ww

Semana do ano

d

Dia

h

Hora

n

Minuto

s

Segundo


date1, date2 - The two date values to be compared.

Date literals allow to specify unambiguous date variables that are independent from the current language. Literals are enclosed between hash signs #. Possible formats are:

firstdayofweek: An optional parameter that specifies the starting day of a week.

firstdayofweek value

Explicação

0

Utilizar o valor do sistema

1

domingo (padrão)

2

segunda-feira

3

terça-feira

4

quarta-feira

5

quinta-feira

6

sexta-feira

7

sábado


firstweekofyear: An optional parameter that specifies the starting week of a year.

firstweekofyear value

Explicação

0

Utilizar o valor do sistema

1

Semana 1 é a semana de 1 de janeiro (padrão)

2

Semana 1 é a primeira semana que contém quatro ou mais dias desse ano

3

Semana 1 é a primeira semana que só contém dias do novo ano


Exemplo:


Sub example_datediff
    MsgBox DateDiff("d", #1/1/2005#, #2005-12-31#)
End Sub

Necessitamos da sua ajuda!