Expression Binding – Date Manipulations


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

Video recorded using: Ignition 7.7


(open in window)

[00:00] We can use the expression language in binding, to make sure that certain property values, get updated every time we open a window on the client. Let's take this example here, I have a start date and a end date, which are both popup calendars, where the user can select the date. I have a table down below, that will show me the history of these five ramp tags, for the time period that we select. So, if I go to the start date and change it, from 03:50 to 03:51 here, for example, Ignition is going to bring back the history, for that time period in table updates. Now the problem is that if I save the window right now, and open the run time, the operator is going to see the start date and the end date, in the same state that I saved it in the designer. So they're going to see it at August 12th from 03:51 to August 12th at 03:52. And that's because there's these two popup calendars, the date property is not bound anything. Properties that are not bound will open up in the client, in the same state that they were saved in the designer. So, that means a year from now or a week from now, the operator will see the date that was older. So, what we want to do is make sure that we open the window, we show the operator the current time, so, that way they make adjustments off of that. We can use the expression language to do this. So, on the end date here, I can actually bind the date property, to an expression, that will give me the current time, will give me now. So, I'm going to basically bring that function in, which is just now. Open parenthesis, I'm going to put a value of zero in there, and an end parenthesis. Then our function can pull, which means it can update automatically for us, and I don't want that to happen, I just want it to update once. So I'm going to put a value of zero in there, which basically says don't pull. As soon as I press OK, it's going to show me the current time on the end date. Now the start date, I want that to be adjustment off of the end date. So I want it to be maybe now, minus 15 minutes, or minus a day. So we're going to bind the date property of that popup calendar, again to another expression, and here we're going to use a different function. If I go to my F of X, and my date and time, I have a function called dataArithmetic which allows me to add or subtract a number from a date. I'm going to bring this function in, the first argument is the date that we want to do the adding or subtraction from. And so what I want to do here, rather than bring in the now function, I want to base it off of the end date popup calendar. So I'm going to and use my property link here to go and bring in the end dates date. Now that I have that, I can then go minus 15 and lastly put maybe minus 15 minutes. So this is the number that we want to add and subtract, and this is the field we want to subtract or add from. So it can be hours, minutes, days, whatever you'd like there. So this here will actually then show me the start date, which is now minus 15 minutes. So we're going to press OK. Now if I save this window, every time it opens up in the run time, the author is going to see it from now minus 15 minutes and then from there, they can make modifications to it.

You are editing this transcript.

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