This is one of those posts that gets put out there to not only help out other developers in the community, but also to give me a spot to reference back to when I need it. Whether you are naming files, doing a timestamp, or displaying it to the user, formatting a DateTime is such a trivial task that is needed quite often. When I am developing in Visual Studio using C# it comes second nature, but when I’m working in Plant an App it can sometimes cause me to pause before I can get the syntax correct, I have, on occasion, resorted to using an Execute Razor action to brute force it. (Definitely the drawbacks of being a developer down to my core.)

Getting a DateTime in the format you want though, is very easy using the proper token syntax.

[DateTime:Now|yyyyMMdd]

or

[DateTime:Utc|yyyyMMdd]

It will take any valid .NET date formatting string that you want to throw at it and as you can see above you can get both your local timezone and UTC. You can find a list here of .NET DateTime formatting options from Microsoft. As far as I know, they all should work just fine. Below are a few more examples of it in use on a Display Message action…..

….and below are the displayed values that appear in the message.

I’m sure I found this in some official documentation at some point, but I have never stumbled across it since. The syntax is so simple that you would think I would always remember it, and hopefully after writing up this post I will, but if not, now we both have a place to go back to reference the syntax.

Need help with a software solution for you business? Contact Us

Comments are closed