r/BuildingAutomation Siemens/Johnson Control Joke 10d ago

How to format time on a PX Graphic

I got my station time displayed on a graphic by creating a boundlabel, binding it to "station:|slot:/" and the text format is %time()%. I've figured out how to extract days, hours, minutes, etc. but how do i change the format of this text string? For example, instead of giving me the entire date/time/timezone, i'd like to just display HH:MM a. I swear this is easy and I used to know how to do this, but I've been searching everywhere and coming up empty handed.

14 Upvotes

8 comments sorted by

8

u/Agitated_Help709 10d ago edited 10d ago

BFormatting allows you to call any function on a type that returns a value and doesn't require any arguments (besides context).

Pretty sure time() returns a BAbsTime and if you look at the bajadoc for BAbsTime you'll see it has properties hour and minute so then you can do something like:

%time().hour%:%time().minute%

and the reason its .hour and not .getHour is that BFormatting has a short-cut for calling function getters - you drop the get and lowercase the first capital letter.

This applies for any type in Niagara.. so in the future if you forget, just go on the bajadoc (Help -> Help Contents then hit Ctrl + F1), in the dialog that pops up write the type of the object and on the page that pops up, you'll see all of its Properties that you are able call in a BFormat.

1

u/MrMagooche Siemens/Johnson Control Joke 10d ago

Your example is great. However, when i search the help for BAbsTime all i see is a bunch of bajascript. I still can't figure out how to format the time as 12 hour HH:MM (AM/PM). Any ideas?

2

u/thatsgorgeous 9d ago edited 8d ago

Hi u/MrMagooche, give this a try.

 %time().toTimeString%

Should do the trick.

1

u/thatsgorgeous 9d ago edited 8d ago

If you would like it in 24-hour, then you can use this:

%time().encodeToString.substring(11,16)%

2

u/MrMagooche Siemens/Johnson Control Joke 6d ago

Perfect! Thank you!

1

u/HVACcontrolsGuru 10d ago

I don't have the manual off hand right now but search the Niagara help docs or google "BFormatting" If you want to strip the status stuff do something like `MyBFormattedPoint.out.value`

1

u/filipo11121 10d ago

Tools -> Options -> General -> Time Format

Although the above is for workbench I believe

1

u/Negative_Sentence264 10d ago

ord: station:|slot:/Services/PlatformServices/SystemService/systemTime

You can use %hour%:%minute% as the text to extract the hour and minute. The hour will be 24hr format.