# Datetime value from Compactlogix

**URL:** <https://forum.inductiveautomation.com/t/datetime-value-from-compactlogix/107425>\
**Category:** Ignition\
**Created:** [June 16, 2025, 3:12pm UTC](https://forum.inductiveautomation.com/t/datetime-value-from-compactlogix/107425 "2025-06-16T15:12:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nol](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@Nol](https://forum.inductiveautomation.com/u/Nol)\
**Post date:** [June 16, 2025, 3:12pm UTC](https://forum.inductiveautomation.com/t/datetime-value-from-compactlogix/107425/1 "2025-06-16T15:12:29Z")

</div>

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

```python
{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](https://www.docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/date-and-time) 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?

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [June 16, 2025, 3:27pm UTC](https://forum.inductiveautomation.com/t/datetime-value-from-compactlogix/107425/2 "2025-06-16T15:27:44Z")

</div>

Try an expression tag with

```python
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.

---

<div class="post-metadata">

**Author:** ![Nol](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@Nol](https://forum.inductiveautomation.com/u/Nol)\
**Post date:** [June 16, 2025, 3:46pm UTC](https://forum.inductiveautomation.com/t/datetime-value-from-compactlogix/107425/3 "2025-06-16T15:46:32Z")

</div>

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