Search code examples
etlspotfiretimespan

Tibco Spotfire - time in seconds & milliseconds in Real, convert to a time of day


I have a list of time in a decimal format of seconds, and I know what time the series started. I would like to convert it to a time of day with the offset of the start time applied. There must be a simple way to do this that I am really missing!

Sample source data:

\Name of source file : 260521-11_58 \Recording from 26.05.2021 11:58 \Channels : 1 \Scan rate : 101 ms = 0.101 sec \Variable 1: n1(rpm) \Internal identifier: 63 \Information1: \Information2: \Information3: \Information4: 0.00000 3722.35645
0.10100 3751.06445
0.20200 1868.33350
0.30300 1868.36487
0.40400 3722.39355
0.50500 3722.51831
0.60600 3722.50464
0.70700 3722.32446
0.80800 3722.34277
0.90900 3722.47729
1.01000 3722.74048
1.11100 3722.66650
1.21200 3722.39355
1.31300 3751.02710
1.41400 1868.27539
1.51500 3722.49097
1.61600 3750.93286
1.71700 1868.30334
1.81800 3722.29224

The Start time & date is 26.05.2021 11:58, and the LH column is elapsed time in seconds with the column name [Time] . So I just want to convert the decimal / real to a time or timespan and add the start time to it.

I have tried lots of ways that are really hacky, and ultimately flawed - the below works, but just ignores the milliseconds.

TimeSpan(0,0,0,Integer(Floor([Time])),[Time] - Integer(Floor([Time])))

The last part works to just get milli / micro seconds on its own, but not as part of the above.


Solution

  • Your formula isn't really ignoring the milliseconds, you are using the decimal part of your time (in seconds) as milliseconds, so the value being returned is smaller than the format mask.

    You need to convert the seconds to milliseconds, so something like this should work

    TimeSpan(0,0,0,Integer(Floor([Time])),([Time] - Integer(Floor([Time]))) * 1000)
    

    To add it to the time, this would work

    DateAdd(Date("26-May-2021"),TimeSpan(0,0,0,Integer([Time]),([Time] - Integer([Time])) * 1000))
    

    You will need to set the column format to

    dd-MMM-yyyy HH:mm:ss:fff