Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Independent validation for trusted, AI-ready data integration. See why IDC named Qlik a Leader: Read the Excerpt!
cancel
Showing results for 
Search instead for 
Did you mean: 
kim-eric
Contributor
Contributor

Simple way to convert time text strings to ints for numeric operation

TimeTemp displays as such 168@06:43:23AM

stationTime displays opening and closing times of service area stations as such 6AM-10AM

I’ve separated TimeTemp into 2 different columns, initialTemp and initialTempTime

I’ve separated stationTime into 2 different columns, openingTime and closingTime

The desired conditional statement is "if not within every 2 hour interval, turn initialTemp cell red", so the logic is as follows:

if(initialTempTime <= openingTime + 2 (hrs), green(), red())

which should turn initialTemp as green if the expression <= is true, else red. However, this has been turning the initialTemp cells all into red.

This got me thinking that the expression is not being evaluated correctly and just defaulting to the else . I’m confident this is the case as initialTempTime , openingTime have been confirmed to be of text string data types.

Since a string + int cannot be evaluated to a truthy, it defaults to red() thus turning all the initialTemp cells into red.

The solution would be to typecast the strings into int, so that openingTime of say 6AM can get added 2 hours and the numeric operation can be properly evaluated.

  • This is where I am getting stuck. What is a simple way to convert time text strings to ints for conditional numeric operations?


    Edit#1:
    Attempts thus far
  • Time#(SubField(stationTime,'-',1),'hh:mm:ss') as openingTimeTest which seems to turn all `openingTime` fields as `-` (null)
  • Num(Sum(SubField(stationTime,'-',1) + tempRecordingInterval)) as openingTimeRecordingInterval where SET tempRecordingInterval=2;
  • Keepchar([initialTempTime],'0123456789.') as [initialTempTimeNum]
Labels (4)
0 Replies