Date conversions...

I need to get the difference between a date stored in a database, retrieved with a statement to read a tPosDate = Recordset.field(“SomeDate”).DateValue.

Using Xojo.core to get the date functions that allow for addition and subtraction results in an error…

For example:

Using Xojo.Core
Dim  ttPosDate As Xojo.Core.Date
Dim NowDate As New Date(1990, 1, 1, TimeZone.Current)
Dim interval As DateInterval
interval = NowDate.Now - tPosDate

I get a class mismatch error: expected Xojo.Core.Date but got class Date

If I include tPosDate under the Xojo.Core.Date declaration then the sql select statement will no longer work…

How do I convert an the ‘old’ style Date into the new Xojo.Core.Date format so that I can calculate the amount of time between the dates?

You’re going to have to convert your tPosDate legacy date to the new format something like

Dim d As New Date ' Legacy Date Using xojo.Core Dim dt As New Date(d.year, d.Month, d.day, TimeZone.Current) ' Converted to xojo.Core.Date

Hi Wayne…
I did the conversion…

It now partly works… For example, the code below:

Dim interval As DateInterval
interval = NowDate.Now - ttPosDate
MsgBox "Years: " + str(interval.Years) + "  Months:  " + str(interval.months)

The MsgBox shows the correct difference between the years, but I have noticed that it is subtracting the days from the months for the second part. the NowDate is in the new framework, while the ttPosDate is from the mysql query. When I show them in the msgbox they seem to be in the same order (ie. YYYY-MM-DD), but like I said, Xojo takes the months and subtracts the days from the second date.?? How do I get it to show the number of months / years difference between the tow dates, one in Xojo.Core format and the other in the Mysql database format?

Thanks!

What version of Xojo? This was a bug in a previous version. It should be fixed in the latest one…

2015r3.1 the latest t hat I have a license for…