CALCULA DE DATAS

LUIS.FLAVIO 29/08/2007 09:43:24
#233183
Pessoal estou com um problema que é da seguinte forma, preciso jogar dentro de um array, um intervalo de datas em um gráfico exemplo.

O usuário vai selecionar 01/01/2007 e quero que o calculo seja doze meses pra frente ou trás se for para frente ficaria assim:

01/01/2007 01/02/2007 01/03/2007 até chegar dezembro.

Agora se for para trás fica 01/01/2006 01/02/2006 até chegar na data 01/01/2007 pois o cálculo foi de 12 meses inferiores.

Obs.: Se o usuário colocar a data de inicio 01/07/2007 até lembro que a automaticamente terá que mudar o ano pois o calcula será de 12 meses.
VILMARBR 29/08/2007 10:49:06
#233195
A função DateAdd não faz esta soma numa boa respeitando ano bissexto, mês com 30 ou 31 dias?

Veja Sintaxe e exemplo abaixo:

DateAdd(interval, number, date)

The DateAdd function syntax has these parts:

Part Description
interval Required. String expression that is the interval you want to add. See Settings section for values.
number Required. Numeric expression that is the number of interval you want to add. The numeric expression 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


The interval argument can have the following values:
Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week of year
h Hour
n Minute
s Second

You can use the DateAdd function to add or subtract a specified time interval from a date. For example, you can use DateAdd to calculate a date 30 days from today or a time 45 minutes from now. To add days to date, you can use Day of Year ("y"), Day ("d"), or Weekday ("w").
The DateAdd function won't return an invalid date. The following example adds one month to January 31:

NewDate = DateAdd("m", 1, "31-Jan-95")

In this case, DateAdd returns 28-Feb-95, not 31-Feb-95. If date is 31-Jan-96, it returns 29-Feb-96 because 1996 is a leap year.
If the calculated date would precede the year 100, an error occurs.

If number isn't a Long value, it is rounded to the nearest whole number before being evaluated.

USUARIO.EXCLUIDOS 29/08/2007 10:52:15
#233196
Vamos lá... creio que não é difícil...

Dim ArDatas() as Date
Redim arDatas(11)

Dim DataInicial as Date
DataInicial = CDate("01/07/2007")

Dim flTipo as Integer
'Aqui vc verifica se é para listar meses anterios ou posterioes
If MesesAnterioes Then
flTipo = -1
Else
flTipo = 1
End If

arDatas(0) = DataInicial
For i = 1 to UBound(arDatas)
arDatas(i) = DateAdd("m",flTipo,arDatas(i - 1))
Next

Tópico encerrado , respostas não são mais permitidas