I have a string value ‘20211228064508000’ in a tag . i want to convert into current date format. I tried to change the data type of tag to Datetime but it didn’t work. Anybody have any solution?
What does it represent ? Is it 2021 12 28 064508000 ?
Expressions might help you convert it to what you want:
https://docs.inductiveautomation.com/display/DOC81/Date+and+Time
edit: Actually the proper question would be: Where does the data come from ? How do you get that string ?
I get that string value from a XML file which is generated by a system . i need to convert this string into datetime format. I tried all the expression but it didn’t work.
Can you tell us more about its format ? Is it 2021 12 28 + time ?
system.date.parse()
should do the trick depending on exactly how the string is to be interpreted.
For instance:
date_string = '20211228064508000'
print system.date.parse(datestring,'yyyyMMddHHmmssSSS')
prints the following:
Tue Dec 28 06:45:08 EST 2021
Note that I’m in the eastern standard time zone and didn’t supply a locale to the function. If you need to convert timezones, you’ll need to provide a local.
Also, I made an assumption about what the substrings meant, if you provide what the expected result of the parsing should be we can provide a more accurate formatString.
That information can all be found at these places:
https://docs.inductiveautomation.com/display/DOC81/system.date.parse
https://docs.inductiveautomation.com/display/DOC81/Data+Type+Formatting+Reference