Please help to find out date difference

I need to find out the number of years, months and days in a between two dates. Could anyone help please

dim d1 as date 'assign some date here dim d2 as date 'some other date here dim DateDiff as integer = d1.totalseconds - d2.totalseconds

Now do a mod with the totalseconds of a year (60 * 60 * 24 * 365) to get the years. Do other mods to get months and days.

Or do

d2.year - d1.year

and so on.

The new framework has dateinterval (http://developer.xojo.com/xojo-core-dateinterval). But the new framework is still not very complete.

For references, here is a very long discussion with several ways :
https://forum.xojo.com/15374-getting-the-date-difference-in-years-months-days/0

[quote=303764:@Beatrix Willius]dim d1 as date 'assign some date here dim d2 as date 'some other date here dim DateDiff as integer = d1.totalseconds - d2.totalseconds

Now do a mod with the totalseconds of a year (60 * 60 * 24 * 365) to get the years. Do other mods to get months and days.

Or do

d2.year - d1.year

and so on.

The new framework has dateinterval (http://developer.xojo.com/xojo-core-dateinterval). But the new framework is still not very complete.[/quote]
Make sure you set the gmtoffsets appropriately.

Thanks all for the advice

You can also use the new Date and DateInterval classes:

Using Xojo.Core Dim d1 As New Date(2016, 12, 16, TimeZone.Current) Dim d2 As New Date(2014, 8, 4, TimeZone.Current) Dim interval As DateInterval = d1 - d2 ' Check interval properties for Years, Months, Days, etc.

You could check out the DateDifferenceMBS class in MBS Plugins:

http://www.monkeybreadsoftware.net/class-datedifferencembs.shtml