Comparing %TimeStamp data types
Hi Guys,
I do have a class where one it's fields is defined as
Set RSet=##class(%ResultSet).%New()
Set Ret=RSet.Prepare(sql)
Set Ret=RSet.Execute()
While RSet.Next()
{ Set routeGuid=""
Set nextScheduled=RSet.GetData(9)
I $ZDATETIME($h,3,1)>nextScheduled S ^badis("datetime",Id)=$ZDATETIME($h,3,1)_"|"_nextScheduled
}
here are the records from my class
and here I should be getting all 12 records,
Thanks
Rochdi, where is the variable Id getting its value? You're setting ^badis("datetime",Id) but I don't see anywhere in your loop where Id gets updated, so maybe you're just overwriting the same value, ^badis("datetime",1), over and over.
sorry missed to copy Set Id=RSet.GetData(1), but it's my original code, and it's not the problem in this case
Hi @Rochdi Badis
Complementing @David Hockenbroch answer, you need to change the If statement, because we can't compare TimeStamp directly, even in the internal format, because in the comparision they are treated like strings.
Use some one of these methods:
$System.SQL.Functions.DATEDIFF
##Class(%Library.UTC).Compare
##Class(%Library.UTC)Diff
Thanks Cristiano
what you need is a SIMPLE compare of two strings
Set Ret=RSet.Execute() set currentTS = $zdt($h,3) // get onece the current timestamp While RSet.Next() { Set routeGuid="" Set nextScheduled=RSet.GetData(9) //I $ZDATETIME($h,3,1)>nextScheduled S ^badis("datetime",Id)=$ZDATETIME($h,3,1)_"|"_nextScheduled if currentTS ] nextScheduled S ^badis("datetime",Id)=currentTS_"|"_nextScheduled }
In words: if currentTS follows (i.e. greater) nextScheduled - that's all.