Platforms to show: All Mac Windows Linux Cross-Platform

/Util/DateDifference/DateDifference Testcases


Required plugins for this example: MBS Util Plugin

Last modified Fri, 20th Feb 2025.

You find this example project in your MBS Xojo Plugin download as a Xojo project file within the examples folder: /Util/DateDifference/DateDifference Testcases

Download this example: DateDifference Testcases.zip

Project "DateDifference Testcases.xojo_binary_project"
Class App Inherits ConsoleApplication
EventHandler Function Run(args() as String) As Integer // year Test New Date(2025, 3, 27, 0, 0, 0), New Date(2026, 03, 27, 0, 0, 0), 1, 0, 0, 0, 0, 0 Test New Date(1980, 3, 27, 0, 0, 0), New Date(2020, 03, 27, 0, 0, 0), 40, 0, 0, 0, 0, 0 // month Test New Date(2025, 2, 27, 0, 0, 0), New Date(2025, 03, 27, 0, 0, 0), 0, 1, 0, 0, 0, 0 Test New Date(2025, 2, 27, 0, 0, 0), New Date(2026, 03, 27, 0, 0, 0), 1, 1, 0, 0, 0, 0 // day Test New Date(2025, 2, 28, 0, 0, 0), New Date(2025, 03, 01, 0, 0, 0), 0, 0, 1, 0, 0, 0 Test New Date(2025, 2, 28, 0, 0, 0), New Date(2025, 03, 02, 0, 0, 0), 0, 0, 2, 0, 0, 0 Test New Date(2025, 2, 27, 0, 0, 0), New Date(2025, 03, 01, 0, 0, 0), 0, 0, 2, 0, 0, 0 Test New Date(2024, 12, 30, 0, 0, 0), New Date(2025, 01, 02, 0, 0, 0), 0, 0, 3, 0, 0, 0 Test New Date(2025, 3, 20, 0, 0, 0), New Date(2025, 4, 10, 0, 0, 0), 0, 0, 21, 0, 0, 0 Test New Date(2025, 4, 20, 0, 0, 0), New Date(2025, 5, 10, 0, 0, 0), 0, 0, 20, 0, 0, 0 Test New Date(2025, 03, 31, 0, 0, 0), New Date(2025, 04, 01, 0, 0, 0), 0, 0, 1, 0, 0, 0 // hour Test New Date(2025, 02, 01, 1, 0, 0), New Date(2025, 02, 01, 2, 0, 0), 0, 0, 0, 1, 0, 0 Test New Date(2025, 02, 01, 23, 0, 0), New Date(2025, 02, 02, 2, 0, 0), 0, 0, 0, 3, 0, 0 Test New Date(2025, 02, 01, 20, 0, 0), New Date(2025, 02, 02, 10, 0, 0), 0, 0, 0, 14, 0, 0 // minute Test New Date(2025, 02, 01, 0, 5, 0), New Date(2025, 02, 01, 0, 10, 0), 0, 0, 0, 0, 5, 0 Test New Date(2025, 02, 01, 0, 20, 0), New Date(2025, 02, 01, 1, 10, 0), 0, 0, 0, 0, 50, 0 // second Test New Date(2025, 02, 01, 0, 0, 0), New Date(2025, 02, 01, 0, 0, 5), 0, 0, 0, 0, 0, 5 Test New Date(2025, 02, 01, 23, 59, 50), New Date(2025, 02, 02, 0, 0, 5), 0, 0, 0, 0, 0, 15 Test New Date(2020, 1, 1, 1, 1, 1), New Date(2021, 02, 02, 2, 2, 2), 1, 1, 1, 1, 1, 1 // a bit more likely to fail due to timezones Var d As New date Var e As New date(d) e.Year = e.Year + 10 Test d, e, 10, 0, 0, 0, 0, 0 e.month = e.month + 10 Test d, e, 10, 10, 0, 0, 0, 0 e.day = e.day + 10 Test d, e, 10, 10, 10, 0, 0, 0 e.hour = e.hour + 10 Test d, e, 10, 10, 10, 10, 0, 0 e.Minute = e.Minute + 10 Test d, e, 10, 10, 10, 10, 10, 0 e.Second = e.Second + 10 Test d, e, 10, 10, 10, 10, 10, 10 Print failed.ToString+" failed" End EventHandler
Sub Test(StartDate as date, EndDate as Date, DiffYear as Integer, DiffMonth as Integer, DiffDay as Integer, DiffHour as Integer, DiffMinute as Integer, DiffSecond as Integer) Var diff As DateDifferenceMBS = StartDate.DifferenceMBS(EndDate) Var okay As Integer = 0 If diff.Year = DiffYear Then okay = okay + 1 Else Break End If If diff.Month = DiffMonth Then okay = okay + 1 Else Break End If If diff.Day = DiffDay Then okay = okay + 1 Else Break End If If diff.Hour = DiffHour Then okay = okay + 1 Else Break End If If diff.Minute = DiffMinute Then okay = okay + 1 Else Break End If If diff.Second = DiffSecond Then okay = okay + 1 Else Break End If If okay = 6 Then // okay Print startdate.SQLDateTime+" And "+EndDate.SQLDateTime+" okay" Else Print startdate.SQLDateTime+" And "+EndDate.SQLDateTime+" failed" failed = failed + 1 End If End Sub
Property failed As Integer
End Class
Sign
End Sign
End Project

See also:

Download this example: DateDifference Testcases.zip

The items on this page are in the following plugins: MBS Util Plugin.


The biggest plugin in space...