Hello All, I intend to display a PI tag whose UoM is seconds to HRS:MM:SS. Any workaround ??
Since you've posted this in PI Developers Club, I'm assuming you are working with SDK code. Essentially you have seconds and want to display as a TimeSpan object. Thus one possibility is a code solution that does just that:
AFValue pv = tag.GetValue();
double seconds = pv.IsGood ? Convert.ToDouble(tag.Value) : 0;
TimeSpan span = TimeSpan.FromSeconds(seconds);
// display span with ToString format that you desire
// display appropriate exception or Digital State
The nice thing about working directly with AF SDK code is you only need one attribute or PI point.
If you are dealing with AF attributes, a TimeSpan is not supported natively but you may define the attribute's data type as Object <Anything>. This does require 2 attributes: one for the Seconds (input) and the other for the TimeSpan (output). You would have to set the values yourself, although you could use Asset Analytics. For example, the difference of 2 timestamps is a TimeSpan object. If you don't have 2 timestamps, or even 1 for that matter, you can fake it out by using a known time and subtracting it from itself. If I did not add and subtract Now below, the TimeSpan would display 123.46 s. But because the expression includes the difference of 2 timestamps, a TimeSpan object is returned.
Rick, I'm going to start calling you Father Time!
About a year ago I saw a reply from Rhys Kirk who mentioned the ability to use an Object as the attribute's data type to hold a TimeSpan. Guess you could say all roads lead back to Rhys!
Thanks for prompt reply. Can this be done with VBA?
If your time span or duration is less than 24 hours, the easiest way with VBA would be to use the Format$() function. With Date variables, it's easy to see in the VBA Editor's Immediate Window:
? Format$(Now, "hh:mm:ss")
May not seem intuitive but you can use the same "hh:mm:ss" format string with Doubles.
? Format$(CDbl(Now), "hh:mm:ss")
Retrieving data ...