Convert an interval (timestamp) to an integer

Can you convert an interval (timestamp) to an integer or number in Tulip?

1 Like

Good suggestion! It is not currently possible to convert a value with data type “interval” to any other data type.

Hello Sathya, Wei,

I’m still loooking on how to covert timestamp to integer as I would like to make calculation (such as OEE). Did you find some workarounds ?

Warm regards,
Patxi

Nevermind Texttonumber() is working just fine !

Great to hear @pte!! That function works great for what you’re trying to achieve. Were you able to set up the triggers to calculate OEE (and others) correctly??

Yes it’s ok thanks Gio :slight_smile:

1 Like

Great @pte. You should share what you built on https://community.tulip.co/c/show-and-tell/9 :link: when you get the chance!!

Hi guys,
Did you create a function for converting an interval (timestamp) to an integer or number? if not, is there any ideas how to do it. I am connected to an ERP and the value i get is an interval. So, i have to convert it to calculate production indicators.
Thank you,

hello @FahdERM, great question!! this can be done using the TEXTTOINTEGER() function.

as you can see in the demo below, the app is calculating the time from now to a User selected start time. following that, the app converts the Interval to an Integer.

completed app:

trigger to store Interval:

trigger to convert Interval to Integer:

here are the app Variables:

please note that the Integer will be in seconds, and can be manipulated to be in the format you need to pass it into your ERP.

hope this helps, let us know if you have further questions.

Hey Gio,

I am also trying to convert interval to integer because I would like to use this logic:

image

I saw that using TEXTTOINTEGER should also converts intervals into an integer:

image

So I thought maybe it work, but then the error said the variable needed to be text, is there an error of this description?

image

hello @ashchav20, thanks for posting!! just to confirm, do you need to calculate the time or the remainder of an integer division?? if it’s the time, I’d recommend using the /, rather than the %.

regarding the error message you’re seeing, it’s being displayed because the function TEXTTOINTEGER() expects a Text Variable or Static Value, so you could first convert the various times you’re using in those functions to Text using the TOTEXT() function within the TEXTTOINTEGER() function. something like this will work:

@App Info.Logged-in User.Name + '. Time spent on app: ' + texttointeger(totext(@App Info.Time Elapsed On Current Step / 3600000))

here’s what it looks like in my app:

could you try that and let me know if it works for you?? thanks!!

Hey @gio,

I am trying to calculate the time and also the remainder of the integer division to show hours, minutes and seconds. I’ll work to integrate you’re recommendation and get back to you, thanks!

Hmm maybe it’s just not possible, it’s ok if not.

image

ah OK, thanks for clarifying @ashchav20!!

in that case the location of the parentheses needs to be changed so the Functions get the correct value types, here’s one way this could be built:

@App Info.Logged-in User.Name + '. Time spent on app: ' + (texttointeger(totext(@App Info.Time Elapsed On Current Step )) % 3600000)


hope this helps!!

1 Like

@gio thank you! It worked!

Do you have a suggestion to only see only the first number in hours, minutes and seconds?

image

Hi Ashley,

I would recommend using the FLOOR() function to take the first of each value. Given that the time elapsed is in number of seconds, both the minute and second values will need to be reactive to the other values. By this, I mean if one hour and one minute passes, you’ll want it to read 1 hour 1 minute, rather than 1 hour, 61 minutes. To do this, each subsequent value will need to subtract out the last one in the same unit (in the same example, 61 minutes would subtract the 60 minutes since 1 hour passed). I’ve set up an example that I’ll share in code below as well as a screenshot of the result. Let me know if this helps!

time

floor(texttonumber(@App Info.Time Elapsed On Current Step ) / 3600) + ' hours ' + floor((texttonumber(@App Info.Time Elapsed On Current Step ) / 60) - (floor(texttonumber(@App Info.Time Elapsed On Current Step ) / 3600) * 60)) + ' minutes ' + floor(texttonumber(@App Info.Time Elapsed On Current Step ) - (floor(texttonumber(@App Info.Time Elapsed On Current Step ) / 60) * 60)) + ' seconds '

Thanks,
Brian

3 Likes

@Brian_Haselton thank you! That did it:

1 Like

@Brian_Haselton my apologies so I only tested this code before it hit any minutes so I thought it was working correctly, but today we had email notifications come through that only kept displaying the seconds but 0 hours and 0 minutes even though our users runtimes were well over an hour. I saw that it worked correctly for you so I’m not sure what the disconnect is.

image

@App Info.Logged-in User.Name + ’ completed ’ + @Variable.Kit Type Selection Variable + ’ ’ + @Variable.Tank or Conveyor? + ’ for ’ + @Variable.Serial Number Select + '. Primary and secondary quality checks were completed. Runtime: ’ + floor(texttonumber(@App Info.Time Elapsed On Current Step ) / 3600) + ’ hours ’ + floor((texttonumber(@App Info.Time Elapsed On Current Step ) / 60) - (floor(texttonumber(@App Info.Time Elapsed On Current Step ) / 3600) * 60)) + ’ minutes ’ + floor(texttonumber(@App Info.Time Elapsed On Current Step ) - (floor(texttonumber(@App Info.Time Elapsed On Current Step ) / 60) * 60)) + ’ seconds. ’