# Filter by Date Optional

**URL:** <https://forum.inductiveautomation.com/t/filter-by-date-optional/10658>\
**Category:** Ignition\
**Created:** [October 23, 2015, 7:08pm UTC](https://forum.inductiveautomation.com/t/filter-by-date-optional/10658 "2015-10-23T19:08:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MoisesZV](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MoisesZV](https://forum.inductiveautomation.com/u/MoisesZV)\
**Post date:** [October 23, 2015, 7:08pm UTC](https://forum.inductiveautomation.com/t/filter-by-date-optional/10658/1 "2015-10-23T19:08:56Z")

</div>

Hi, I’m trying to filter a table, but I want an optional filter by date. I have a custom property in my table called “dateFilter”, this is the expression:

```auto
if({Root Container.checkbox.selected}=1,"and date between '{Root Container.startDate.date}' and '{Root Container.endDate.date}'","and 1=1")
```

When the checkbox =1 the custom property equals “and date between ‘{Root Container.startDate.date}’ and ‘{Root Container.endDate.date}’” and when the checkbox =0 the custom property equals “1=1”

I have this query in my table

```auto
SELECT * FROM tags WHERE tag LIKE '%{Root Container.tagFilter.text}%' {Root Container.Table.dateFilterwhere} ORDER BY fecha DESC 
```

When I set the checkbox to 1 the filter it seems to work but its not show any data in my table.

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [October 23, 2015, 7:16pm UTC](https://forum.inductiveautomation.com/t/filter-by-date-optional/10658/2 "2015-10-23T19:16:07Z")

</div>

You might have to use the ‘dateFormat’ function to get the dates into a format your database likes.

---

<div class="post-metadata">

**Author:** ![Pat](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@Pat](https://forum.inductiveautomation.com/u/Pat)\
**Post date:** [October 23, 2015, 8:06pm UTC](https://forum.inductiveautomation.com/t/filter-by-date-optional/10658/3 "2015-10-23T20:06:53Z")

</div>

The expression thinks your property bindings are part of the string, you need to pull the property bindings out of the string. Also the checkbox selected evaluates to true or false so you can just use the property, you don’t have to say =1.

Try -

```auto
if({Root Container.checkbox.selected},"and date between '" + {Root Container.startDate.date} + "' and '" + {Root Container.endDate.date} + "'","and 1=1")
```

---

<div class="post-metadata">

**Author:** ![MoisesZV](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@MoisesZV](https://forum.inductiveautomation.com/u/MoisesZV)\
**Post date:** [October 26, 2015, 1:12pm UTC](https://forum.inductiveautomation.com/t/filter-by-date-optional/10658/4 "2015-10-26T13:12:47Z")

</div>

[quote=“Pat”]The expression thinks your property bindings are part of the string, you need to pull the property bindings out of the string. Also the checkbox selected evaluates to true or false so you can just use the property, you don’t have to say =1.

Try -

```auto
if({Root Container.checkbox.selected},"and date between '" + {Root Container.startDate.date} + "' and '" + {Root Container.endDate.date} + "'","and 1=1")
```

Thanks Pat, that solved my problem, when I pull the property bindings out of the string it worked. Thanks!
