Convert old Date to Xojo.Core.Date

  1. 4 years ago

    Scott R

    23 Aug 2015 Pre-Release Testers, Xojo Pro

    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.

  2. Mike C

    23 Aug 2015 Pre-Release Testers, Xojo Pro North Carolina (USA)

    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
  3. Norman P

    23 Aug 2015 Xojo Inc, Pre-Release Testers, Xojo Pro Seeking work. npalardy@great-w...

    @Scott R 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?

    You cant cast one to the other
    You can convert one to / from the other but it involves code like Mike posted

  4. Eli O

    is not verified 24 Aug 2015 Europe (Berlin, Germany)
    Dim d As New Xojo.Core.Date(aClassicFrameworkDate.TotalSeconds - 2082844800, Xojo.Core.TimeZone.Current)
  5. Mike C

    24 Aug 2015 Pre-Release Testers, Xojo Pro North Carolina (USA)

    Eli thank you!

  6. Greg O

    24 Aug 2015 Xojo Inc scout.galaxy.barn

    Make sure you consider time zone when you make this conversion. The old date format wasn't very particular about them, but the new one is.

  7. Bob K

    16 Jun 2016 Pre-Release Testers, Xojo Pro Kansas City

    @Eli O Dim d As New Xojo.Core.Date(aClassicFrameworkDate.TotalSeconds - 2082844800, Xojo.Core.TimeZone.Current)

    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?

  8. Eli O

    is not verified 16 Jun 2016 Europe (Berlin, Germany)

    Classic dates are GMT dates I assume. So you would need to apply the offset:

    Dim d As New Xojo.Core.Date(aClassicFrameworkDate.TotalSeconds - 2082844800 - Xojo.Core.TimeZone.Current.SecondsFromGMT, Xojo.Core.TimeZone.Current)

    And some time zones have daylight saving time – I don't know how these influence TimeZone and SecondsFromGMT.

  9. Michel B

    17 Jun 2016 Pre-Release Testers, Xojo Pro

    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
  10. Bob K

    17 Jun 2016 Pre-Release Testers, Xojo Pro Kansas City

    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.

  11. Michel B

    17 Jun 2016 Pre-Release Testers, Xojo Pro

    @Bob K 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 ?

  12. Bob K

    17 Jun 2016 Pre-Release Testers, Xojo Pro Kansas City

    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.

  13. Brock N

    17 Jun 2016 Pre-Release Testers, Xojo Pro

    What's the best way to go in reverse? I need to go from a Xojo.Core.Date to the classic Date.

  14. Michel B

    17 Jun 2016 Pre-Release Testers, Xojo Pro
    Edited 4 years ago

    I tend to use exactly the same way I posted : use the constructor with explicit values. But the root property is probably OK too.

  15. Norman P

    17 Jun 2016 Xojo Inc, Pre-Release Testers, Xojo Pro Seeking work. npalardy@great-w...

    the classic date constructor with appropriate params passed seems simple enough

  16. Peter F

    21 Jun 2016 Pre-Release Testers, Xojo Pro New England

    @Bob K 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.

    Guilty :)

    Tested, but, obviously not extensively enough.

  17. Bob K

    21 Jun 2016 Pre-Release Testers, Xojo Pro Kansas City

    @Peter F Guilty :)

    Tested, but, obviously not extensively enough.

    No worries. Easy to miss because it does bring back a date that looks good at first blush. Unfortunately, a client was the one that spotted it. :(

  18. 2 years ago

    Djamel A

    25 Jul 2018 Oran (Algeria)

    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.

  19. Björn E

    25 Jul 2018 Pre-Release Testers, Xojo Pro Iceland

    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.

    Basically same as any other control works

  20. Ulrich B

    25 Jul 2018 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    @Djamel A;AMRANE These values changes only inside valueChanged Event (Date and Time ctrl), i would like to get the values changed every where in the project.

    You should read about AddHandler. It allows you to reroute an event to another place.

  21. Newer ›

or Sign Up to reply!