Android Question Difference between VB6 and B4A Date calculations

Syd Wright

Well-Known Member
Licensed User
I have encoded dates by means of a VB6 program, e.g.:

Private Sub Form_load()
Dim Date1 As Date
Dim Date2 As Date
Dim Result1 as Long
Date1 = Format(Date, "dd/MM/yyyy")
Date2 = Format(Date, "dd/MM/yyyy")
Date1 = "01/01/0100"
Date2 = "05/08/1964"
Result1= DateDiff("d", Date1, Date2)
End Sub

Date1 is 01/01/0100, which is the lowest possible reference date in VB6
The result is 681028 days (which I have encoded as 3 bytes to save space in a database).

When I try to recalculate Date2 in B4A the result is 03/08/1964 in stead of 05/08/1964 (2 days off).
I do this with:
Dim Dticks1, Dticks2 as long
Dim Days1 as long
Days1 = 681028
DateTime.DateFormat = "dd/MM/yyyy"
Dticks1 = DateTime.DateParse("01/01/0100")
Log(DateTime.Date(Dticks1 + (Days1* DateTime.TicksPerDay)))
'Both methods give the wrong result

'Calculating the number of days in B4A:
Dticks1 = DateTime.DateParse("01/01/0100")
Dticks2 = DateTime.DateParse("05/08/1964")
'The Result is 681030, compared to 681028 with VB6!

It probably has to do with leap years. The number of ticks-per-day are the same in VB6 and B4A: 86400000. How can this be resolved?

PS: This website also gives 681030, so B4A seems to be correct and VB6 is wrong:
Last edited:

Syd Wright

Well-Known Member
Licensed User
The correct way to calculate time differences is with DateUtils.PeriodBetween.
Thank you. The problem is in VB6. I have now solved it by generating a list in B4A with the Ticks values for the 1st of January of each year from the year 0001 to 2200. I import this list in VB6, read the Ticks value for that year and then add the Ticks value between the 1st of January and the actual day in that year (with the VB6 datediff function).
This solves my problem.
Upvote 0