# Using Jython Script to Iterate through a date range

**URL:** <https://forum.inductiveautomation.com/t/using-jython-script-to-iterate-through-a-date-range/5292>\
**Category:** Ignition\
**Created:** [October 18, 2012, 9:34pm UTC](https://forum.inductiveautomation.com/t/using-jython-script-to-iterate-through-a-date-range/5292 "2012-10-18T21:34:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jconnor34](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@jconnor34](https://forum.inductiveautomation.com/u/jconnor34)\
**Post date:** [October 18, 2012, 9:34pm UTC](https://forum.inductiveautomation.com/t/using-jython-script-to-iterate-through-a-date-range/5292/1 "2012-10-18T21:34:24Z")

</div>

I have a date range using two strings: startDate and endDate.

I want to write a script to iterate through each and every day between the startDate and endDate, inclusive. The version of Jython in Ignition doesn’t support the datetime library. I have looked into using an import of java.util but don’t get very far when trying to convert the string to a java Calendar object.

The reason for this script is to be able to iterate through a date range and for each day in the range do a historical tag query with a specific time range. Currently the system.tag.queryTagHistory function does not a where clause to filter each day by a time frame so I am forced to iterate through each day in a date range.

Thanks.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 18, 2012, 9:54pm UTC](https://forum.inductiveautomation.com/t/using-jython-script-to-iterate-through-a-date-range/5292/2 "2012-10-18T21:54:04Z")

</div>

Just to be sure: you’re on 7.3 or earlier then right? 7.4 and later use Jython 2.5, which does include datetime.

---

<div class="post-metadata">

**Author:** ![jconnor34](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@jconnor34](https://forum.inductiveautomation.com/u/jconnor34)\
**Post date:** [October 18, 2012, 9:55pm UTC](https://forum.inductiveautomation.com/t/using-jython-script-to-iterate-through-a-date-range/5292/3 "2012-10-18T21:55:51Z")

</div>

Yes, I am on version 7.3.

---

<div class="post-metadata">

**Author:** ![jconnor34](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@jconnor34](https://forum.inductiveautomation.com/u/jconnor34)\
**Post date:** [October 18, 2012, 10:38pm UTC](https://forum.inductiveautomation.com/t/using-jython-script-to-iterate-through-a-date-range/5292/4 "2012-10-18T22:38:18Z")

</div>

I think I figured it out.

---

<div class="post-metadata">

**Author:** ![dave.fogle](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dave.fogle](https://forum.inductiveautomation.com/u/dave.fogle)\
**Post date:** [October 18, 2012, 11:38pm UTC](https://forum.inductiveautomation.com/t/using-jython-script-to-iterate-through-a-date-range/5292/5 "2012-10-18T23:38:46Z")

</div>

Glad you got it figured out. Let us know if you need any additional help with this.

---

<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 19, 2012, 1:54am UTC](https://forum.inductiveautomation.com/t/using-jython-script-to-iterate-through-a-date-range/5292/6 "2012-10-19T01:54:53Z")

</div>

You could always create a calendar table in the database and query it for the dates. It’ll return a dataset with all the dates, that’s easy to iterate through.
