Question
Rochdi Badis · Sep 14, 2022

Comparing %TimeStamp data types

Hi Guys,

I do have a class where one it's fields is defined as %TimeStamp and I did query to select all records and if current datetime is bigger then what's in my nextScheduled filed and basically with this condition below I should have all records stored in ^badis but for some reason I'm only getting the first record   

 sql="Select ID,CollectTimeOut,KitId,ComponentId,Loc,IntervalValue,IntervalType,LastScheduled,NextScheduled,Schedule,StartDate,StartTime,SensorId,SensorType from MSDS_Common.JobSchedule"
 Set RSet=##class(%ResultSet).%New()
 Set Ret=RSet.Prepare(sql)
 Set Ret=RSet.Execute()
 While RSet.Next()
  { Set routeGuid="" 
Set nextScheduled=RSet.GetData(9)
$ZDATETIME($h,3,1)>nextScheduled ^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

Product version: Ensemble 2014.1
0
0 136
Discussion (5)2
Log in or sign up to continue

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
   

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.