When using system.date.parse with formats other than the standard, it returns whatever dates it feels like, everything but what it should!
E.g.
system.date.format(
system.date.parse('20250312_120000', 'YYYYMMdd_HHmmss')
)
>>
u'2024-12-29 12:00:00' (or Sun Dec 29 12:00:00 ACDT 2024)
???
Ok nevermind... apparently "YYYY" should be "yyyy" 
Java thinks Y is "Week Year" and y is Year... good job Java for being different....
First time using Ignition 
3 Likes
Yep, I had used 'YYYY' for years before discovering it. We're usually on shutdown between Christmas and New Year's, so it was a self inflicted bug that didn't show itself for a very... long... time.
2 Likes
It's funny, there are at least 4 different date format formats I've found so far in Ignition:
- Python, not that you should use its datetime objects (
%Y-%M
or something)
- Java (
yyyy-MM-dd HH:mm:ss
- lowercase y)
- Expression function dateFormat (
yyyy-MM-dd HH:mm:ss
- lowercase y, same as Java)
- SQL (ok, not really Ignition) (
YYYY-MM-dd HH:mm:ss
- normal)
- Perspective Tables (
YYYY-MM-DD HH:mm:ss
- DDs)
2 Likes
Also:
- Expression function
stringFormat("%tY-%<tm-%<td %<tH:%<tM:%<tS", someDateObj)
or
- Expression function
stringFormat("%tF %<tT", someDateObj)
( From java.util.Formatter
)
I tend to use a variant of that last, because when formatting dates, you are usually also formatting other things. And those work in Ignition's logger's .debugf()
, .infof()
and similar methods.
1 Like