Description

Learn how to manipulate dates in expression bindings such as a date addition/subtraction with the dateArithmetic function.

Video recorded using: Ignition 8.1

Transcript

(open in window)

[00:00] In this lesson, I'll demonstrate how to add an expression binding that manipulates a date. I have a Vision window in my project that displays some tag history data in a Power Table. The Power Table is set up with a historical tag history binding where the start and end dates are bound to these two pop-up calendars. If I save the window as it currently is, anytime someone launches a client and opens up this window, the popup calendars will display the currently selected dates. That means that in a couple days, or even in a couple months from now, they'll open up this window and see tag history data for this time period, which will be in the past. I'd like to change this so that the initial timeframe reflects the current date whenever it's opened. To make this dynamic, I'll add an expression binding. I'll start with the calendar for the end date. I want this to load with the current date, so we use the now expression function. Since I want the operator to be able to change this, I don't want it to poll and refresh, so I'm gonna make the poll rate zero so it only loads the first time when the windows opened.

[01:07] I'll click okay and then add another expression to the start date calendar. For this one, I want it to load so that the table reflects tag history data for the last 15 minutes. I'll use the date arithmetic expression function. To accomplish this, I'll find the function from the date and time list, and we can see that it takes three parameters. The first will be the date that's being manipulated, so I use the property selector to select the end date. Then the other parameters control how the date is manipulated. The second parameter is the number of units I'm going to manipulate the date by, and the third parameter is a string of what unit that will be. For example, I want the start date to be 15 minutes earlier than the end date, so negative 15 will be the second parameter, and then the third parameter will be minutes in quotes. I'll add my closing parentheses and click okay. Now, whenever this window is opened in the client, the table will automatically show data for the last 15 minutes and can then be modified if necessary. Right now, the start date will update automatically if the end date is changed, but if I didn't want them to be linked, I could change the expression so that the now expression is used instead of the end date reference.

[02:34] Now I have a dynamic date selection on my window that I was able to quickly set up with the help of an expression binding.

You are editing this transcript.

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