# How things work - passing Date value via query string parameter gotcha

**URL:** <https://forum.inductiveautomation.com/t/how-things-work-passing-date-value-via-query-string-parameter-gotcha/75884>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [July 4, 2023, 8:51am UTC](https://forum.inductiveautomation.com/t/how-things-work-passing-date-value-via-query-string-parameter-gotcha/75884 "2023-07-04T08:51:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [July 4, 2023, 8:51am UTC](https://forum.inductiveautomation.com/t/how-things-work-passing-date-value-via-query-string-parameter-gotcha/75884/1 "2023-07-04T08:51:29Z")

</div>

hi  
I am trying to improve my understanding of time formats when using named queries. It tripped me a few times in the past so enough is enough 🙂  
For example:  
1 in named query i try to pass current timestamp parameter so i created querystring parameter to hold that value.  
2 when testing named query i used system.date.now() in script console to have an example of the date which i passed as a parameter to text (i added single quotes as the date has to be passed as a string). System.time.now() resulted in "Tue Jul 04 09:39:58 BST 2023" The named query did not work  
3 i formatted system.time.now output using system.date.format function which printed as "2023-07-04 09:39:58" When passed to the named query it did work.

I read somewhere that using curly braces (which are used when passing querystring parameter in the named query) somehow breaks the date.  
Could anybody please share their understanding of:  
1 are there any good practices when passing dates via Named Query?  
2 why passing formatted output of the system.date.now did work but when it was not formatted it did not work? i understand that system.date.format produces string and this string system converted to date which was possible when using formatted date and impossible when using raw output - is it right?  
3 when i changed parameter from querystring to value and selected data type and pasted the output of system.date.now - the query did not work as well - i am not sure why -database column is using datetime parameter so it should work 🙂 - pls see second screenshot

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/1/914721a25a5685035612f5bef9c9b7047b9c4d94.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/e/deffc94cfe4f06cb6cc9bea0ab4c7f8c2599373f.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 4, 2023, 9:04am UTC](https://forum.inductiveautomation.com/t/how-things-work-passing-date-value-via-query-string-parameter-gotcha/75884/2 "2023-07-04T09:04:37Z")

</div>

disclaimer: I'm only speculating here

1. Why use query strings for this ? You're passing a date, that's a value. Use the `date` type and you'll be fine
2. If you're passing a string instead of a date, the database engine can handle conversion. But not for any format. The error in your first screenshot makes it clear: It didn't recognize the format, so the conversion failed.
3. After you formatted the date to a particular format that it recognizes, the conversion worked, and the query ran succesfully.

---

<div class="post-metadata">

**Author:** ![Learner\_Ignition](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Learner\_Ignition](https://forum.inductiveautomation.com/u/Learner_Ignition)\
**Post date:** [July 4, 2023, 9:41am UTC](https://forum.inductiveautomation.com/t/how-things-work-passing-date-value-via-query-string-parameter-gotcha/75884/3 "2023-07-04T09:41:53Z")

</div>

I have 2 parameters for report i.e startdate and enddate and set the data type to string and have a default datetime value as string, and I had bind this 2 values from a namedquery where i am getting date time in yyyy-MM-dd HH:mm:ss format.  
Then I used this 2 parameters to run a basic query to get datas for the report.

When I set the datatype of startdate and endate as date and pass date time value I get error.

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [July 4, 2023, 10:18am UTC](https://forum.inductiveautomation.com/t/how-things-work-passing-date-value-via-query-string-parameter-gotcha/75884/4 "2023-07-04T10:18:07Z")

</div>

very sound logic - thanks

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [July 4, 2023, 10:22am UTC](https://forum.inductiveautomation.com/t/how-things-work-passing-date-value-via-query-string-parameter-gotcha/75884/5 "2023-07-04T10:22:54Z")

</div>

i suggest the following:  
1 select parameter type as "Query String"  
2 test your named query in ignition -paste the formatted date string wrapped in single quotes eg.  
'2023-07-04 09:39:58 as one of parameteres

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 4, 2023, 11:43am UTC](https://forum.inductiveautomation.com/t/how-things-work-passing-date-value-via-query-string-parameter-gotcha/75884/6 "2023-07-04T11:43:24Z")

</div>

Well... What's the error ?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 4, 2023, 1:05pm UTC](https://forum.inductiveautomation.com/t/how-things-work-passing-date-value-via-query-string-parameter-gotcha/75884/7 "2023-07-04T13:05:34Z")

</div>

Query string parameters are _ **STRINGS** _. Converting a datetime type to string usually loses information, and then requires parsing to recover.

FWIW, if you are using any querystring parameters in a named query, you are defeating the security advantages using value parameters provides. Under no circumstances should user-generated values ever be allowed in a querystring parameter.

Pass your datetime values as value parameters. Full stop.

If you have dates/times already in strings, convert them to datetime values using a system function with an explicit format conversion, then pass the resulting datetime objects as value parameters.

---

<div class="post-metadata">

**Author:** ![hewking32](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@hewking32](https://forum.inductiveautomation.com/u/hewking32)\
**Post date:** [July 4, 2023, 1:19pm UTC](https://forum.inductiveautomation.com/t/how-things-work-passing-date-value-via-query-string-parameter-gotcha/75884/8 "2023-07-04T13:19:16Z")

</div>

that info gets me sorted - thanks again
