ToDate action item

I have an action item set up to look at integer values from the PLC and convert them to a date.

ToDate({Int1}+"-"+{Int2}+"-"+{Int3}+" "+{Int4}+":"+{Int5}+":"+{Int6})

This triggers and works fine sometimes. Every once in a while I get the following error,
“String was not recognized as valid DateTime” This causes the group to hang, since it is set-up to handshake and only execute once. Any suggestions?

I would imaging that the error is occurring at certain times and the date parser doesn’t like it- for example, maybe when the seconds are in single digits. Or, is it possible that some values are coming in that are bigger than they should be, or that you have two fields swapped?

I guess the first thing to do would be to figure out if the failure corresponds to any particular pattern.

In regards to the group not running again, could you use the failure handshake to indicate that an error occurred/reset the trigger? This situation has actually been a known issue for a while, and in the next update “run once” triggers won’t be allowed to latch on failed executions.

Regards,

You probably need to format your integers as two characters (month, day, hour, minute, second) or four characters (year).

Try one of these:

ToDate(Substring(Concat("0", ToString({Int1})), If({Int1}<9, 0, 1)) + "-" + Substring(Concat("0", ToString({Int2})), If({Int2}<9, 0, 1)) + "-" + Substring(Concat("000", ToString({Int3})), Len(ToString({Int3})) - 1) + " " + Substring(Concat("0", ToString({Int4})), If({Int4}<9, 0, 1)) + ":" + Substring(Concat("0", ToString({Int5})), If({Int5}<9, 0, 1)) + ":" + Substring(Concat("0", ToString({Int6})), If({Int6}<9, 0, 1)))

or

ToDate(Substring(Concat("0", ToString({Int1})), Len(ToString({Int1})) - 1) + "-" + Substring(Concat("0", ToString({Int2})), Len(ToString({Int2})) - 1) + "-" + Substring(Concat("000", ToString({Int3})), Len(ToString({Int3})) - 1) + " " + Substring(Concat("0", ToString({Int4})), Len(ToString({Int4})) - 1) + ":" + Substring(Concat("0", ToString({Int5})), Len(ToString({Int5})) - 1) + ":" + Substring(Concat("0", ToString({Int6})), Len(ToString({Int6})) - 1))

These assume the year (i.e., {Int3}) is 2009 or similar value instead of 9 or similar value.

I know this is a lot more complicated but it should work.