Xojo Date Math

      No Comments on Xojo Date Math

Xojo is a great programming language that is simple to get started with, but powerful enough that you won’t find a limit with what you can do.

That being said, doing date math seems to be more difficult than it should be. And the documentation in this area seems to be lacking. Probably because there are *so* many examples that would be needed. I think most programmers have some sort of class or module that helps them accomplish various date calculations.

We had our Atlanta Xojo Users Group meeting last night and a question came up that I thought was a great opportunity to talk about Xojo Date Math. This programmer is migrating from the programming language Clarion over to Xojo. The Clarion databases store their dates as a form of Julian date where an integer indicates the number of days since December 28th, 1800. I opened up Xojo and created a simple desktop application where the TextChange event of a TextBox calls a function that displays a date. The value of the TextBox is an example of days since the start of the Clarion day zero. Here is the method that takes the number of days and then returns a Xojo date object.

Private Function ClarionToXojoDate(nDaysToAdd AS Integer) as xojo.core.date

Dim d1800 As New Xojo.Core.Date( 1800, 12, 28, Xojo.Core.TimeZone.Current )

Dim dDifference AS New Xojo.Core.DateInterval( 0, 0, nDaysToAdd )

DIM dNewDate AS Xojo.Core.Date = d1800 + dDifference

RETURN dNewDate
End Function

I hope that this little sample helps people out where they are wanting to add (or subtract) dates from some starting point.