Datetime value from Compactlogix

I'm trying to read a datetime value from our PLC but keep getting expression errors and unsure what I'm doing wrong. The format in the PLC is a time array so I have individual int's reading each of them into my Ignition UDT which seem to be working fine. However I can't seem to package those into a datetime tag to attach to a label.

PLC:
OPC / Integer type

{plc_tag}.SD_DateTime_Active.Mo
{plc_tag}.SD_DateTime_Active.Da
{plc_tag}.SD_DateTime_Active.Hr
{plc_tag}.SD_DateTime_Active.Min
{plc_tag}.SD_DateTime_Active.Sec
{plc_tag}.SD_DateTime_Active.mSec
{plc_tag}.SD_DateTime_Active.uSec

I don't need/care about mSec/uSec but can use them if required for the formatting.

Ignition Expressiong DateTime type:
date([{[.]SD_DateTime_Active_bits/Yr},{[.]SD_DateTime_Active_bits/Mo}-1,{[.]SD_DateTime_Active_bits/Da},{[.]SD_DateTime_Active_bits/Hr},{[.]SD_DateTime_Active_bits/Min},{[.]SD_DateTime_Active_bits/Sec})

Is this possible to do in the tag itself or should I go about using an actual script on the label instead?

Edit: Reading this link I'm realizing date() isn't a valid function is my issue and I don't see any options to create a datetime value. So a script on the label itself may be the only route?

Try an expression tag with

setTime(
	getDate(
		{[.]SD_DateTime_Active_bits/Yr},
		{[.]SD_DateTime_Active_bits/Mo}-1,
		{[.]SD_DateTime_Active_bits/Da}
	),
	{[.]SD_DateTime_Active_bits/Hr},
	{[.]SD_DateTime_Active_bits/Min},
	{[.]SD_DateTime_Active_bits/Sec}
)

There is no single expression function for making a datetime value, but you can combine expression functions pretty freely. Breaking it down, you first make a date without a time stamp, then set the time on that date.

2 Likes

Thanks so much, that's exactly what I was missing and couldn't wrap my head around.