I know I’m overthinking this one but how would I go about casting an old Date object to the new Xojo.Core.Date object?
I purchased a control (encrypted) that returns the selected date (old object) but date manipulation routines I have created use the new framework. Not sure how to get the returned date into a new Xojo.Core.Date.
I just tested this and I am also researching any built in functions to see if there is a more efficient way to accomplish this.
HTH. (I tied this to a button action to test quickly).
// GET OLD FRAMEWORK DATE
Dim d as New Date
Dim dString as String = d.SQLDateTime
// CONVERT TO NEW FRAMEWORK DATE
Using Xojo.Core
Dim dateValue As Text = dString.ToText
Dim myDate As Date = Date.FromText(dateValue)
MsgBox "New Framework Date: " + myDate.ToText
[quote=209136:@Scott Rich]I know I’m overthinking this one but how would I go about casting an old Date object to the new Xojo.Core.Date object?
[/quote]
You cant cast one to the other
You can convert one to / from the other but it involves code like Mike posted
I’m not sure where this came from, but this consistently brings back the wrong date for me. For example, if the date in the database is 1962-02-18 00:00:00 it likes to bring back 1962-02-17 00:00:00. Has anyone else experienced this?
Actually Classic date is using the current Locale.
dim d as new date
system.debuglog d.SQLDateTime
Dim dada as new Xojo.core.date(d.year, d.month, d.day, d.hour, d.Minute, d.Second, 0, Xojo.Core.TimeZone.Current)
system.debuglog dada.totext
I had a bug report from (other peoples) code that used the above snippet and found that the above snippet consistently brought back the wrong date. No big deal to move it to using the global Date object. This is a warning for others that might use it verbatim as the person who wrote this code did.
Which snippet ? The totalsecond one, or the constructor with year, month, day, hour, etc ?
Whichever one it seems pretty easy to verify after constructing the Xojo.Core.Date if it is in sync with Classic. Could it rather not be an issue with the conversion between totalsecond and secondsFrom1970 ?
The first snippet. And yes, it’s a conversion issue between total second’s and secondsFrom1970.
The OPC project I was working on I could tell that the programmer took the code, verbatim, from this post and used it without checking its authenticity. The dangers of using code you find online.
Hello,
Using TimeControl and DateControl (EinHugur Plugin), i try to get time and Date valueChanged
These values changes only inside valueChanged Event (Date and Time ctrl), i would like to get the values changed every where in the project.
I am not sure what you are asking you get notify in the event when the value changes and you there notify the rest of your application and variables of the change.
If you for any reason want to read the value at random time then you just read the controls DateValue property.