[Gambas-user] DateAdd function

Benoit Minisini gambas at ...1...
Sun Aug 15 09:51:08 CEST 2004


On Sunday 15 August 2004 09:26, VBTricks.de.vu Webmaster wrote:
> Hi Benoit,
>
> I read your comment. As I do not have the MSDN available under Linux, I
> tried adding years using "y" as intervall. With "yyyy" it works. But
> when trying to add months to a date, the function fails.
>
> My source:
> Dim NextDate As Date
> NextDate = CDate("10/03/03") ' October 3rd, 2003
> NextDate = vb.DateAdd("m", 2, NextDate)
>
> 'should return December 3rd, 2003
>
> Error displayed: "Invalid Date Returned"
>
> But this date does exist!
>
> So where's the fault?

There is a bug in the function.

As a workaround, do that:

DIM iMonth AS Integer
DIM iYear AS Integer

NextDate = CDate("10/03/03")
iYear = Year(NextDate)
iMonth = Month(NextDate) + 2
IF iMonth > 12 THEN
  iMonth = iMonth - 12
  INC iYear
ENDIF
NextDate = Date(iYear, iMonth, Day(NextDate))

The vb.DateAdd function is not strictly necessary, as it can be written with 
the functions Date(), Year(), Month(), Day(), and so on...

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the User mailing list