# Format datetime from system.tag.queryTagHistory

**URL:** <https://forum.inductiveautomation.com/t/format-datetime-from-system-tag-querytaghistory/90577>\
**Category:** Ignition\
**Created:** [May 17, 2024, 8:13pm UTC](https://forum.inductiveautomation.com/t/format-datetime-from-system-tag-querytaghistory/90577 "2024-05-17T20:13:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Craig\_webber](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/craig_webber/32/62546_2.png) [@Craig\_webber](https://forum.inductiveautomation.com/u/Craig_webber)\
**Post date:** [May 17, 2024, 8:13pm UTC](https://forum.inductiveautomation.com/t/format-datetime-from-system-tag-querytaghistory/90577/1 "2024-05-17T20:13:50Z")

</div>

I am running some tag queries against a postgres TimeScaleDB

My data is coming back with millisecond resolution when I run 1 minute average queries:  
"t\_stamp","XXXXX",  
"2024-05-04 00:02:00.028","0.2266050743890813",  
"2024-05-04 04:52:04.088","5.7324847185309595"

There is a slight drift in the seconds of the timestamps and this is causing the data team that uses these CSV exports problems I need to get all the time stamps to just be in the yyyyMMdd HH:mm format .  
what are my options to get this done ? I don't see any way to format the timestamp in the query. I am really hoping I dont have to loop through the returned data set and modify each row as these queries usually have 3-4million rows.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 17, 2024, 8:16pm UTC](https://forum.inductiveautomation.com/t/format-datetime-from-system-tag-querytaghistory/90577/2 "2024-05-17T20:16:13Z")

</div>

Why are your timestamps coming back as strings?  
Can you post your query? See [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [May 17, 2024, 8:46pm UTC](https://forum.inductiveautomation.com/t/format-datetime-from-system-tag-querytaghistory/90577/3 "2024-05-17T20:46:28Z")

</div>

If your datatype is really timestamp, it should be coming back as a long. It could be that whatever you're using to view the data is doing some autoformatting for you (for example, if you're displaying it in something that expects a date).

If it really is a long, and you really need a formatted date, postgres can format it in the query by using the [to\_char(timestamp) function](https://www.postgresql.org/docs/current/functions-formatting.html).

---

<div class="post-metadata">

**Author:** ![Craig\_webber](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/craig_webber/32/62546_2.png) [@Craig\_webber](https://forum.inductiveautomation.com/u/Craig_webber)\
**Post date:** [May 17, 2024, 8:47pm UTC](https://forum.inductiveautomation.com/t/format-datetime-from-system-tag-querytaghistory/90577/4 "2024-05-17T20:47:32Z")

</div>

Oh cant get the query right now but what I pasted above for the timestamps is after I run The dataset.toCSV() hopefully that answers your question

---

<div class="post-metadata">

**Author:** ![Craig\_webber](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/craig_webber/32/62546_2.png) [@Craig\_webber](https://forum.inductiveautomation.com/u/Craig_webber)\
**Post date:** [May 17, 2024, 8:50pm UTC](https://forum.inductiveautomation.com/t/format-datetime-from-system-tag-querytaghistory/90577/5 "2024-05-17T20:50:05Z")

</div>

Is this an option when im using system.tag.queryTagHistory()

---

<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:** [May 17, 2024, 9:12pm UTC](https://forum.inductiveautomation.com/t/format-datetime-from-system-tag-querytaghistory/90577/6 "2024-05-17T21:12:07Z")

</div>

Make sure that your start timestamp for your query has no seconds or milliseconds, and that the end timestamp for your query ends with :59.999. The return size should be exactly the number of minutes in that span.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [May 17, 2024, 9:29pm UTC](https://forum.inductiveautomation.com/t/format-datetime-from-system-tag-querytaghistory/90577/7 "2024-05-17T21:29:42Z")

</div>

doh, you're right. I blame it on being Friday afternoon of a verrrrry long week.

---

<div class="post-metadata">

**Author:** ![Craig\_webber](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/craig_webber/32/62546_2.png) [@Craig\_webber](https://forum.inductiveautomation.com/u/Craig_webber)\
**Post date:** [May 21, 2024, 6:23pm UTC](https://forum.inductiveautomation.com/t/format-datetime-from-system-tag-querytaghistory/90577/8 "2024-05-21T18:23:01Z")

</div>

Thanks this was the answer. this is exactly how I fixed it:  
self.view.custom.startTime and self.view.custom.endTime are date/time components

```python
startTime = system.date.parse(self.view.custom.startTime.formattedValue, "yyyy-MM-dd HH:mm")
endTime = system.date.parse(self.view.custom.endTime.formattedValue, "yyyy-MM-dd HH:mm")

```
