# setTime/getDate error

**URL:** <https://forum.inductiveautomation.com/t/settime-getdate-error/74438>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [June 1, 2023, 1:52pm UTC](https://forum.inductiveautomation.com/t/settime-getdate-error/74438 "2023-06-01T13:52:39Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![lyhkch](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lyhkch/32/9381_2.png) [@lyhkch](https://forum.inductiveautomation.com/u/lyhkch)\
**Post date:** [June 1, 2023, 1:52pm UTC](https://forum.inductiveautomation.com/t/settime-getdate-error/74438/1 "2023-06-01T13:52:39Z")

</div>

Hi, how to solve these error:  
setTime function expected a 'date' first argument, but got null  
getDate function expected a 'int' first argument, but got null

I have check the tags scripts，like this "getDate({[.]START\_YEAR},{[.]START\_MONTH},{[.]START\_DAY})", and three tags are ok.  
 ![Snipaste_2023-06-01_21-51-04](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/1/8140207d5a89a70183849b744184a22bcbd82d0d.jpeg)

---

<div class="post-metadata">

**Author:** ![Tim\_Carlton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim_carlton/32/52835_2.png) [@Tim\_Carlton](https://forum.inductiveautomation.com/u/Tim_Carlton)\
**Post date:** [June 1, 2023, 1:57pm UTC](https://forum.inductiveautomation.com/t/settime-getdate-error/74438/2 "2023-06-01T13:57:17Z")

</div>

Are those references going to return qualified values instead of integers?

---

<div class="post-metadata">

**Author:** ![lyhkch](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lyhkch/32/9381_2.png) [@lyhkch](https://forum.inductiveautomation.com/u/lyhkch)\
**Post date:** [June 3, 2023, 2:04am UTC](https://forum.inductiveautomation.com/t/settime-getdate-error/74438/3 "2023-06-03T02:04:09Z")

</div>

I will give a integers

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 3, 2023, 8:37am UTC](https://forum.inductiveautomation.com/t/settime-getdate-error/74438/4 "2023-06-03T08:37:30Z")

</div>

Show us your `setTime()` expression.

Use backticks ` to format code, not double-quotes ". You can also format code using the \</\> button.

---

<div class="post-metadata">

**Author:** ![lyhkch](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lyhkch/32/9381_2.png) [@lyhkch](https://forum.inductiveautomation.com/u/lyhkch)\
**Post date:** [June 5, 2023, 11:18am UTC](https://forum.inductiveautomation.com/t/settime-getdate-error/74438/5 "2023-06-05T11:18:27Z")

</div>

Hi，I use it in UDT tags' Expression.  
 ![Snipaste_2023-06-05_19-16-59](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/9/197411f850fe9456bd83ab309511402d61e7c395.jpeg)  
 ![Snipaste_2023-06-05_19-16-17](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/0/d0ad66da6aad4ad99fb7e3c2ae44463550715890.jpeg)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 5, 2023, 11:43am UTC](https://forum.inductiveautomation.com/t/settime-getdate-error/74438/6 "2023-06-05T11:43:01Z")

</div>

Post formatted code, not pictures of code. (That way we don't have to type it all out in our answers.)

Correct syntax is `setTime()`, not `settime`.

To debug your `getDate()` error try changing your expression binding to `{[.]START_DATE}` and see what it returns in the preview at the bottom of the binding window.  
If that looks OK then change it to `typeOf({[.]START_DATE})` and see if the value is an integer.

---

<div class="post-metadata">

**Author:** ![Tim\_Carlton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim_carlton/32/52835_2.png) [@Tim\_Carlton](https://forum.inductiveautomation.com/u/Tim_Carlton)\
**Post date:** [June 5, 2023, 12:56pm UTC](https://forum.inductiveautomation.com/t/settime-getdate-error/74438/7 "2023-06-05T12:56:53Z")

</div>

Where are you setting these expressions?

If you are using the Expression Editor then you might try using the pick tools on the right side. They will give you the proper syntax for the methods and the proper reference for the tags.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/9/c94e77d5ca591f84979a64db9bda32d59ea2f935.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/b/7b4ac886b8dfd7a1b26e0ada6c5401a479238237.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/6/8664d56c3e51743f8ccedde09114fe3642d9454d.png)

---

<div class="post-metadata">

**Author:** ![Tim\_Carlton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim_carlton/32/52835_2.png) [@Tim\_Carlton](https://forum.inductiveautomation.com/u/Tim_Carlton)\
**Post date:** [June 5, 2023, 1:38pm UTC](https://forum.inductiveautomation.com/t/settime-getdate-error/74438/8 "2023-06-05T13:38:29Z")

</div>

As a UDT:

UDT definition

```auto
{
  "name": "DateFromIntsUdt",
  "tagType": "UdtType",
  "tags": [
    {
      "valueSource": "expr",
      "expression": "typeOf({[.]Day})",
      "dataType": "String",
      "name": "TypeOfDay",
      "value": "",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "memory",
      "name": "Month",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "memory",
      "name": "Hour",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "memory",
      "name": "Year",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "memory",
      "name": "Day",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "memory",
      "name": "Second",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "memory",
      "name": "Minute",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "expr",
      "expression": "getDate({[.]Year},{[.]Month}-1,{[.]Day})",
      "dataType": "DateTime",
      "name": "DateOut",
      "formatString": "yyyy-MM-dd h:mm:ss aa",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "expr",
      "expression": "setTime({[.]DateOut},{[.]Hour},{[.]Minute},{[.]Second})",
      "dataType": "DateTime",
      "name": "DateTimeOut",
      "formatString": "yyyy-MM-dd HH:mm:ss",
      "tagType": "AtomicTag"
    }
  ]
}

```

Tag Definition

```auto
{
  "name": "StartDateTimeUdt",
  "typeId": "DateFromIntsUdt",
  "tagType": "UdtInstance",
  "tags": [
    {
      "value": 55,
      "name": "Second",
      "tagType": "AtomicTag"
    },
    {
      "value": 23,
      "name": "Minute",
      "tagType": "AtomicTag"
    },
    {
      "formatString": "yyyy-MM-dd HH:mm:ss",
      "name": "DateTimeOut",
      "tagType": "AtomicTag"
    },
    {
      "name": "TypeOfDay",
      "tagType": "AtomicTag"
    },
    {
      "name": "DateOut",
      "tagType": "AtomicTag"
    },
    {
      "value": 8,
      "name": "Hour",
      "tagType": "AtomicTag"
    },
    {
      "value": 4,
      "name": "Day",
      "tagType": "AtomicTag"
    },
    {
      "value": 6,
      "name": "Month",
      "tagType": "AtomicTag"
    },
    {
      "value": 2023,
      "name": "Year",
      "tagType": "AtomicTag"
    }
  ]
}

```

The values in the UDT default to null in my example:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/2/92afb8b823c1f6486e2662ee145e01800320f5d7.png)

And I get the error in the log:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/4/a498af21cb5fb74289752f3a2e2ca8a1c094df5a.png)

But the tag itself works just fine when I fill in actual values:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/a/9af9f56cc984eaffafe5d3ec6bced09c236b0664.png)

---

<div class="post-metadata">

**Author:** ![Tim\_Carlton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim_carlton/32/52835_2.png) [@Tim\_Carlton](https://forum.inductiveautomation.com/u/Tim_Carlton)\
**Post date:** [June 5, 2023, 3:27pm UTC](https://forum.inductiveautomation.com/t/settime-getdate-error/74438/9 "2023-06-05T15:27:15Z")

</div>

UDT that accepts tag paths for the inputs and does some range validation (February 30 is accepted but February 32 is not).

```auto
{
  "name": "DateFromIntsUdt",
  "parameters": {
    "DayTagPath": {
      "dataType": "String"
    },
    "MinuteTagPath": {
      "dataType": "String"
    },
    "SecondTagPath": {
      "dataType": "String"
    },
    "YearTagPath": {
      "dataType": "String"
    },
    "HourTagPath": {
      "dataType": "String"
    },
    "MonthTagPath": {
      "dataType": "String"
    }
  },
  "tagType": "UdtType",
  "tags": [
    {
      "valueSource": "expr",
      "expression": "if(tag({MinuteTagPath})\u003e59 || tag({MinuteTagPath}) \u003c 0,qualifiedValue(tag({MinuteTagPath}),\u0027bad\u0027,524,\u0027Minute must be between 0 and 59\u0027),tag({MinuteTagPath}))",
      "name": "ValidatedMinute",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "expr",
      "expression": "if(tag({YearTagPath})\u003edateExtract(now(),\u0027year\u0027)+2 || tag({YearTagPath})\u003cdateExtract(now(),\u0027year\u0027)-2,qualifiedValue(tag({YearTagPath}),\u0027bad\u0027,524,\u0027Year must be within two years of the current year\u0027),tag({YearTagPath}))",
      "name": "ValidatedYear",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "expr",
      "expression": "if(tag({DayTagPath})\u003e31 || tag({DayTagPath}) \u003c 1,qualifiedValue(tag({DayTagPath}),\u0027bad\u0027,524,\u0027Day must be between 1 and 31\u0027),tag({DayTagPath}))",
      "name": "ValidatedDay",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "expr",
      "expression": "if(tag({MonthTagPath})\u003e12 || tag({MonthTagPath}) \u003c 1,qualifiedValue(tag({MonthTagPath}),\u0027bad\u0027,524,\u0027Month must be between 1 and 12\u0027),tag({MonthTagPath}))",
      "name": "ValidatedMonth",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "expr",
      "expression": "getDate({[.]ValidatedYear},{[.]ValidatedMonth},{[.]ValidatedDay})",
      "dataType": "DateTime",
      "name": "DateOut",
      "formatString": "yyyy-MM-dd h:mm:ss aa",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "expr",
      "expression": "setTime({[.]DateOut},{[.]ValidatedHour},{[.]ValidatedMinute},{[.]ValidatedSecond})",
      "dataType": "DateTime",
      "name": "DateTimeOut",
      "formatString": "yyyy-MM-dd h:mm:ss aa",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "expr",
      "expression": "if(tag({HourTagPath})\u003e23 || tag({HourTagPath}) \u003c 0,qualifiedValue(tag({HourTagPath}),\u0027bad\u0027,524,\u0027Hour must be between 0 and 23\u0027),tag({HourTagPath}))",
      "name": "ValidatedHour",
      "tagType": "AtomicTag"
    },
    {
      "valueSource": "expr",
      "expression": "if(tag({SecondTagPath})\u003e59 || tag({SecondTagPath}) \u003c 0,qualifiedValue(tag({SecondTagPath}),\u0027bad\u0027,524,\u0027Second must be between 0 and 59\u0027),tag({SecondTagPath}))",
      "name": "ValidatedSecond",
      "tagType": "AtomicTag"
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![lyhkch](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lyhkch/32/9381_2.png) [@lyhkch](https://forum.inductiveautomation.com/u/lyhkch)\
**Post date:** [June 5, 2023, 3:45pm UTC](https://forum.inductiveautomation.com/t/settime-getdate-error/74438/10 "2023-06-05T15:45:37Z")

</div>

Yes, I use getDate or setTime , also works fine, but error in the logs. So, I want to know why?

---

<div class="post-metadata">

**Author:** ![lyhkch](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lyhkch/32/9381_2.png) [@lyhkch](https://forum.inductiveautomation.com/u/lyhkch)\
**Post date:** [June 5, 2023, 3:55pm UTC](https://forum.inductiveautomation.com/t/settime-getdate-error/74438/11 "2023-06-05T15:55:56Z")

</div>

There will be a lot of error messages constantly generated, whether it will take up a lot of system resources

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 5, 2023, 4:04pm UTC](https://forum.inductiveautomation.com/t/settime-getdate-error/74438/12 "2023-06-05T16:04:14Z")

</div>

Can you step back for a moment and explain what problem you're trying to solve? There's probably a better way than this.

---

<div class="post-metadata">

**Author:** ![Tim\_Carlton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim_carlton/32/52835_2.png) [@Tim\_Carlton](https://forum.inductiveautomation.com/u/Tim_Carlton)\
**Post date:** [June 5, 2023, 4:05pm UTC](https://forum.inductiveautomation.com/t/settime-getdate-error/74438/13 "2023-06-05T16:05:37Z")

</div>

In my test I see one error in the log when I save the UDT definition in Designer.  
I don't see any errors when I provide valid values to the tags.

You haven't really given us enough to go on. No code, no indication of what you have tried, etc.

Maybe try to validate the tags (like in my last example except include explicit tests for null, Bad Quality, etc.) and use clues in the results to figure out why it is happening. Use those results in your expression to avoid doing the conversion when you have bad data.

Good luck.
