Corde Date compare problem

Hello all,

I am want to compare two core dates. I am trying to increment the first date in a loop until its greater than the second date. I have simplified my code down and still don’t understand why it won’t work. It seems to bump the date up properly but falls out of the loop after one pass. It’s probably something simple but i’m not seeing it. I’d appreciate any help.

Thanks

Using xojo.core
dim di as new xojo.Core.DateInterval

dim iDateIncriment as Date = xojo.core.date.Now
dim iDateEnd as Date = xojo.core.date.Now

di.Days = 1

iDateIncriment = Date.FromText(“2016-07-30”)
iDateEnd = Date.FromText(“2016-12-31”)

do until iDateIncriment > iDateEnd

iDateIncriment = iDateIncriment + di

loop

do until iDateIncriment.SQLDATE > iDateEnd.SQLDATE

or totalseconds , but I prefer SQLDATE if just the date portion, or SQLDATETIME if down to the second

and you need to increment either

  • totalseconds
  • year
  • day
  • minute
    or
  • second

I didn’t know the new Xojo.Core.Date had an SQLDate property.

I did not find an SQLDATE property ? I thought you could just compare two core dates straight out. Am I mistaken?

It does not.

I read carefully the LR page, there is apparently no direct comparison.

You can use the core property secondsfrom1970 for your comparison :

[code] Using xojo.core
dim di as new xojo.Core.DateInterval

dim iDateIncriment as Date = xojo.core.date.Now
dim iDateEnd as Date = xojo.core.date.Now

di.Days = 1

iDateIncriment = Date.FromText(“2016-07-30”)
iDateEnd = Date.FromText(“2016-12-31”)

do until iDateIncriment.SecondsFrom1970 > iDateEnd.SecondsFrom1970

iDateIncriment = iDateIncriment + di

loop

system.DebugLog iDateIncriment.ToText[/code]

Thanks to all who replied! Tried “Seconds” and "SecondsFrom1970.That seemed to do the trick. Both worked. I thought that was just to get more precise and not necessary.

Thanks to all !

Just an update :

Adding SecondsFrom1970 allowed the date to increment properly but the date compare failed to function properly when it should have exited the loop. This is what finally worked:

Using xojo.core
dim di as new xojo.Core.DateInterval

dim iDateIncriment as Date = xojo.core.date.Now
dim iDateEnd as Date = xojo.core.date.Now

di.Days = 1

iDateIncriment = Date.FromText(“2016-07-30”)
iDateEnd = Date.FromText(“2016-12-31”)

do until mid(iDateIncriment.ToText,1,10) > mid(iDateEnd.ToText,1,10)

iDateIncriment = iDateIncriment + di

loop

Thanks again to everyone !

Seriously? That is a huge detrement to SQL processing in my opinion…

Guess once the “current” framework is totally deprecated in favor of this “new” one, it when it will be time to move on… which would be a shame…

and for those of you using iOS, and MUST use the new frame work…

here are simple SWIFT extensions to NSDATE, feel free to translate them to a declare or plugin or whatever

  var SQLDate:String {
        set {
            //  let fmt=NSDateFormatter()
            fmt.dateFormat=fmt_SQLDate
            var tempStr:String=newValue

            // Ignore any TIME component
            if tempStr.Len()>fmt_SQLDate.Len() {
                tempStr=(tempStr as NSString).substringWithRange(NSRange(location:0,length:fmt_SQLDate.Len()))
            }
            if let temp=fmt.dateFromString(tempStr) {
                assign_date(NSDate(timeInterval: 0, sinceDate: temp))
            } else {
                mERROR=true
            }
        }
        get {
            //   let fmt=NSDateFormatter()
            fmt.dateFormat=fmt_SQLDate
            return String(fmt.stringFromDate(theDate))
        }
    }
    var SQLDateTime:String {
        set {
            var tempStr:String=newValue
            //   let fmt=NSDateFormatter()
            // Append a bogus Time, if one is not supplied
            if tempStr.Len()<fmt_SQLDateTime.Len() {
                tempStr=tempStr+" 00:00:00"
            }
            fmt.dateFormat=fmt_SQLDateTime
            if let temp=fmt.dateFromString(tempStr) {
                assign_date(NSDate(timeInterval: 0, sinceDate: temp))
            } else {
                mERROR=true
            }
        }
        get {
            //   let fmt=NSDateFormatter()
            fmt.dateFormat=fmt_SQLDateTime
            return String(fmt.stringFromDate(theDate))
        }
    }

oh… just noticed there are references here to other parts of a much larger DATE class I wrote, but you get the idea

i

It isn’t called that, but to be clear to others reading this thread that functionality certainly exists- the new framework has standardized on FromText/ToText to transform things from/to text. SQLDateTime format is a common textual representation and thus you can just do a FromText or ToText on a Xojo.Core.Date without needing to pass any kind of other format and you’re off to the races.