Problem splitting a split

I have an expression tag called DateTimeString in a UDT instance that contains a string value for a date and time in the following format… MM/DD/YYYY HH:MM:SS.

I have another expression tag that is also a string type, and in its expression I am trying to split the date from the datetime, then split the month from the date.

I started out splitting out the date from the datetime with the following expression…

split({[.]DateTimeString}, ’ ')[0,0]

This works fine. The split creates a dataset and I select the first row and first column to give the date only as the value for this tag. So then I expanded it to break out the month with a nested split using the following expression…

split(split({[.]DateTimeString}, ’ ')[0,0], ‘/’)[0,0]

This does not work and gives null for the value and an evaluation error for the quality. Just for grins, I tried substituting a hard-coded string in place of the DateTimeString tag as shown below, but it gives the same error.

split(split(‘01/02/2013 14:15:16’, ’ ')[0,0], ‘/’)[0,0]

Does anyone know why this doesn’t work?

Rather than doing the split logic, check out dateFormat and dateExtract expression functions.

It would be so nice to be able to use that instead, but unfortunately the date and time are not always formatted as I showed in this description. I didn’t want to confuse the matter. I am having to take the date apart and reassemble it so that it looks consistent on a template.

The date and time are acquired via OPC from a device that can be one of nine different models from two different manufacturers. Four of the models format their date as YYYY/MM/DD. Three of them format it as YYYY-MM-DD. And the other two format it as DD/MM/YY.

The time is another matter, with some using leading zeros on the hours and minutes and seconds, some without the leading zeroes, and some using no leading zeros and using AM and PM instead of military time. It’s such a joy when there are no standards.

Kudos to Anna Christian from IA Support. :prayer: She figured this out for me. It appears that you cannot nest two splits as I tried to do, and as many programming languages allow you to do. It appears that the expression language here in Ignition gets a bit confused, so she had to trick it into parsing correctly.

This is the expression that didn’t work…

split(split({[.]DateTimeString}, ’ ')[0,0], ‘/’)[0,0]

Anna added a cast of the second split to a string, as shown below…

split(toStr(split({[.]DeviceTimeString}, ’ ')[0,0]), ‘/’)[0,0]

and this works as desired. Thank you, Anna.