Displaying 6 digit DINT tag value as HH:MM:SS

I have a tag that displays time as HHMMSS. How can i display this 6 digit number as a time, i.e. 14:22:35. I’m not sure its even possible but I thought I would ask. Thanks!

I want to do the same with a tag that has an 8 digit vale for YYYYMMDD for the date.

I’m not 100% but I think this is what you are looking for Transforms - Ignition User Manual 8.0 - Ignition Documentation

Perspective or Vision?

1 Like

An expression tag with this expression in it does the desired formatting. Update “timestamp” tag reference in it to match your integer tag path.

dateFormat(
	setTime(
		now(),
		floor({[.]timestamp}/10000),
		floor({[.]timestamp}%10000/100),
		{[.]timestamp}%100
	),
	"HH:mm:ss"
)

image

For date stamp, use expression below. We subtract one from the month as getDate function numbers months 0-11 instead of 1-12. We don’t need to use floor here assuming month and day numbers are never high enough to round up into larger units (unlike minutes and seconds in timestamp).

dateFormat(
	getDate(
		{[.]datestamp}/10000,
		{[.]datestamp}%10000/100 - 1,
		{[.]datestamp}%100
	),
	"yyyy-MM-dd"
)

image

Both examples are taking integers and breaking them into components of a date/time, using them to set date/time, and then formatting the date/time per format string in quotes in second last line of expressions. You can change the format string to get different results.

The examples above are done in expression tags, but you could do the same conversions in component expression bindings (Vision), or binding transforms (Perspective).

3 Likes

vision

Use the modulo and division operations @witman shows, but format with stringFormat("%02d:%02d:%02d", ...).

2 Likes