Increase a date

Hi all
Xojo
Very grateful for your answers

I have an initial date and a final date

how can I increase the initial date by one day each time until the initial date is equal to the final date

Cordially,

Raul

With classic date you can do:

d.Day = d.Day + 1

[code]Dim initialDate As Date = New Date
Dim finalDate As Date = New Date(2018, 10, 13, 0, 0, 0)

'If your dates have times in them, set them the same so the compare will work nicely

initialDate.Hour = 0
initialDate.Minute = 0
initialDate.Second = 0

finalDate.Hour = 0
finalDate.Minute = 0
finalDate.Second = 0

Dim d As Date = initialDate

While d <= finalDate
system.DebugLog(str(d))
d.Day = d.Day + 1
Wend[/code]

Inifinitas Thanks
Alberto De Poo
JulianS

With your help solved the problem
Blessings
Raul

If you look at Julian’s code it has a comment about the dates’ times. I think you can use d.SQLDate

One caveat about Julian’s code

Dim d As Date = initialDate

While d <= finalDate
  system.DebugLog(str(d))
  d.Day = d.Day + 1
Wend

This will modify the value of InitialDate as well as d. If you need to keep the value of InitialDate intact, use

Dim d As new Date
 d.TotalSeconds= initialDate.TotalSeconds

While d <= finalDate
  system.DebugLog(str(d))
  d.Day = d.Day + 1
Wend

or similar. I think there’s a constructor that copies dates, but I always use my own function so I can suppress the time elements of the date and just deal with month/day/year.

I’m still learning. Sometimes things are not clear. Is great that is possible to do thing in many different ways. I haven’t needed to use time with dates as yet, that’s why I like d.SQLDate.

This will be my code with SQLDate:

[code]Dim initialDate As New Date
Dim finalDate As New Date(2018, 10, 13)

Dim d As New Date
d.SQLDate = initialDate.SQLDate

While d.SQLDate <= finalDate.SQLDate
System.DebugLog(Str(d.SQLDate))
d.Day = d.Day + 1
Wend[/code]