Forum Academy Marketplace Showcase Pricing Features

Converting date interval field into fractions of a second

I’m trying to measure how much time it takes a user to complete a certain activity in my app. Each user’s score will be compared against other users, and the lowest time wins.

The problem I’m running into is that I can’t find a way to break down time values into anything less than whole number seconds. For example, I can’t distinguish between 35.6 and 35.7 seconds - they both get rounded to 36.

I’m storing two date fields for the start and stop times, and then I’ve tried saving the difference between them as a date interval. But even though the documentation says that date intervals are stored as milliseconds, there does not seem to be a way to do math on these values manually. My only option is to round to the nearest whole number of seconds, which doesn’t work for my use case.

Can anybody advise on a plugin or workaround way of solving this? Thanks in advance for your help.

1 Like

Hello @nucleusrobotics welcome back!

This expression converts a date into seconds (or more importantly for your use case … a number)

Thanks for the response, but I don’t think that can be used on a date interval value from the database. You are using that on the current date/time, which doesn’t solve my problem.

The only options I have to convert a date interval value are shown below (and it’s the same options for a date value or for the result of subtracting two date values):

Screen Shot 2022-01-10 at 12.20.38 PM

Actually correction - it looks like you CAN use that on a regular date value. So it appears that the limitation is only for date interval types. I believe this will solve my problem if I just don’t use the date interval field type and store it as a number instead.

Thanks for your help @cmarchan

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.