Expression Binding – Format Date


Learn how to format a date in an expression binding using the dateFormat and now functions.

Video recorded using: Ignition 7.7


(open in window)

[00:00] We can use the expression language to format a date and display any way that we want on the screen. Let's show the current time to the user, the format to a particular pattern that makes sense to them. Let's take a label component and drag it onto our window and make it larger. We combine the text property of the label to an expression. In the expression language we have various functions, some of which are date and time functions. We have two functions here we're going to use. One is the date and format which will actually take a date and format to a particular pattern. The second is now which will turn us the current date. So the date format function has two arguments, it has the date that we want to format and then the pattern that we want to use. I'm going to use this one first, click on that it's going to bring in date format, open parentheses. So the first argument is the actual date that we want to format and for that, I'm going to use the current time. I could also of course bring in a date from a screen if we had it on the screen. I'm going to go back to the f of x functions, I'm going to go down to date and time and bring in the now function. Now we turns as the current time, has one argument which is the poll rate which is how often you want this binding to update. If I'm going to bring it in, now open parentheses, I'm going to put a value of 1000 which means it's going to update every one second. Imma end parentheses to complete that function. As you can see we're just nesting one function inside of another function. So the second argument of the date format is the actual format itself. We're going to do that as a string. I'm going to put double quotes in there, I'm going to paste in my, my date format and then end parentheses at the very end. You can refer to user manual to know what various letters you could put in here to how you want to display that date. A basic idea is my three capital Ms is the month, imma display it as like August or September, the D is my day of the month, the Y is our, the year, hours, minutes, and seconds, and then am or pm at the very end. So now that I have this and make sure you end your parentheses to close out those functions once you have that you press okay, you can now see the current time updating every one second the way that you want it to be shown to the user.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.