setTime/getDate error

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

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

1 Like

I will give a integers

Show us your setTime() expression.

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

Hi,I use it in UDT tags' Expression.
Snipaste_2023-06-05_19-16-59
Snipaste_2023-06-05_19-16-17

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.

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.

1 Like

As a UDT:

UDT definition

{
  "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

{
  "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

And I get the error in the log:

But the tag itself works just fine when I fill in actual values:
image

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

{
  "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"
    }
  ]
}

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

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

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

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.