# ISO8061 Date Time Format

**URL:** <https://forum.inductiveautomation.com/t/iso8061-date-time-format/87605>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [March 20, 2024, 2:32am UTC](https://forum.inductiveautomation.com/t/iso8061-date-time-format/87605 "2024-03-20T02:32:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sasi\_Rai](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@Sasi\_Rai](https://forum.inductiveautomation.com/u/Sasi_Rai)\
**Post date:** [March 20, 2024, 2:32am UTC](https://forum.inductiveautomation.com/t/iso8061-date-time-format/87605/1 "2024-03-20T02:32:19Z")

</div>

Dear All,

I have a dataset with just 2 columns: Date/TIme and Values.

The date/time, I found out, is in ISO format, like, "2024-03-20T23:00:00Z". This is not recognized by Ignition.

system.dataset.formatDates() threw an error.

I need to correct the date/time to Igntion accepted format. How can I do it?

I was thinking of:

- creating a dataset with 2 columns and assigning headings
- from each row of the old dataset, reading the date/time and converting, copying the value and adding these as a row in the new dataset.

Or are there any other better quicker ways? Thanks.

---

<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:** [March 20, 2024, 8:45am UTC](https://forum.inductiveautomation.com/t/iso8061-date-time-format/87605/2 "2024-03-20T08:45:59Z")

</div>

To be clear: You get dates as strings, and you want to convert them to actual datetime objects, right ?

Then you'll need to parse them with `system.date.parse`.  
`formatDates` is there to take a datetime object as input, and output a string representing that datetime in a specific format.

Datetimes objects do not have formats. Only their string representations do.  
But since, in order to see them, they have to be represented... they're represented with some format, that actually has nothing to do with the date itself.

so, something like

```python
system.date.parse(d, "yyyy-MM-dd'T'HH:mm:ss'Z'")

```

---

<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:** [March 20, 2024, 9:13am UTC](https://forum.inductiveautomation.com/t/iso8061-date-time-format/87605/3 "2024-03-20T09:13:14Z")

</div>

Also be aware that 'Z' indicates that the time is UTC or "Zero time zone". You may need to take this into account in your application and handle both time zone and daylight savings - if applicable.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 20, 2024, 1:56pm UTC](https://forum.inductiveautomation.com/t/iso8061-date-time-format/87605/4 "2024-03-20T13:56:53Z")

</div>

> [@Sasi\_Rai](#):
>
> I was thinking of:
> 
> - creating a dataset with 2 columns and assigning headings
> - from each row of the old dataset, reading the date/time and converting, copying the value and adding these as a row in the new dataset.

You will need to do this as the original dataset is immutable.

> [@Transistor](#):
>
> Also be aware that 'Z' indicates that the time is UTC or "Zero time zone".

java.time.Instant can take care of that:

```python
sampleHeaders = ['t_stamp', 'value']
sampleData = [['2024-03-20T23:00:00Z', 5],
              ['2024-03-20T23:10:00Z', 4],
              ['2024-03-20T23:20:00Z', 3],
              ['2024-03-20T23:30:00Z', 2],
              ['2024-03-20T23:40:00Z', 1]
             ]

sampleDataSet = system.dataset.toDataSet(sampleHeaders, sampleData)

############################################################

from java.time import Instant
from java.util import Date

def zuluTimeToDate(dateIn):
	return system.date.fromMillis(Instant.parse(dateIn).toEpochMilli())
	
dataIn = sampleDataSet

headers = list(dataIn.columnNames)
data = []
for row in xrange(dataIn.rowCount):
	data.append([zuluTimeToDate(dataIn.getValueAt(row,0)), dataIn.getValueAt(row,1)])

dataOut = system.dataset.toDataSet(headers, data)

```

```plaintext
row | t_stamp | value
------------------------------------------
0 | Wed Mar 20 19:00:00 EDT 2024 | 5    
1 | Wed Mar 20 19:10:00 EDT 2024 | 4    
2 | Wed Mar 20 19:20:00 EDT 2024 | 3    
3 | Wed Mar 20 19:30:00 EDT 2024 | 2    
4 | Wed Mar 20 19:40:00 EDT 2024 | 1    

```

EDIT:  
java.text.SimpleDateFormat will work too.

```python
sampleHeaders = ['t_stamp', 'value']
sampleData = [['2024-03-20T23:00:00Z', 5],
              ['2024-03-20T23:10:00Z', 4],
              ['2024-03-20T23:20:00Z', 3],
              ['2024-03-20T23:30:00Z', 2],
              ['2024-03-20T23:40:00Z', 1]
             ]

sampleDataSet = system.dataset.toDataSet(sampleHeaders, sampleData)

############################################################

from java.text import SimpleDateFormat

dataIn = sampleDataSet

dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX")

headers = list(dataIn.columnNames)
data = []
for row in xrange(dataIn.rowCount):
	data.append([dateFormat.parse(dataIn.getValueAt(row,0)), dataIn.getValueAt(row,1)])

dataOut = system.dataset.toDataSet(headers, data)

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 20, 2024, 3:42pm UTC](https://forum.inductiveautomation.com/t/iso8061-date-time-format/87605/5 "2024-03-20T15:42:48Z")

</div>

What Jordan said, although I'd expect a pure-dataset approach to be a _little_ faster than building a new dataset via Python objects:

> [@Can I modify an entire column from a dataset with system.dataset.setValue()?](https://forum.inductiveautomation.com/t/can-i-modify-an-entire-column-from-a-dataset-with-system-dataset-setvalue/87043/3):
>
> def mapColumn(function, dataset, column): if isinstance(column, basestring): column = dataset.getColumnIndex(column) columnData = map(function, dataset.getColumnAsList(column)) columnsToKeep = range(dataset.columnCount) columnsToKeep.pop(column) dsWithoutColumn = system.dataset.filterColumns(dataset, columnsToKeep) return system.dataset.addColumn( dsWithoutColumn, column, columnData, dataset.getColumnName(column), dataset.getColumnType(column) ) It's relatively easy to…

Though the example script I have there doesn't support changing the column types. I'll leave that as an exercise for the reader 🙂

---

<div class="post-metadata">

**Author:** ![Sasi\_Rai](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@Sasi\_Rai](https://forum.inductiveautomation.com/u/Sasi_Rai)\
**Post date:** [March 21, 2024, 11:52pm UTC](https://forum.inductiveautomation.com/t/iso8061-date-time-format/87605/6 "2024-03-21T23:52:42Z")

</div>

Thanks. I will give it a try.

---

<div class="post-metadata">

**Author:** ![Sasi\_Rai](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@Sasi\_Rai](https://forum.inductiveautomation.com/u/Sasi_Rai)\
**Post date:** [March 21, 2024, 11:56pm UTC](https://forum.inductiveautomation.com/t/iso8061-date-time-format/87605/7 "2024-03-21T23:56:30Z")

</div>

Thanks a lot Jordan! Much appreciated.

I will try these out one by one, will take me some time though. 😃

---

<div class="post-metadata">

**Author:** ![Sasi\_Rai](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@Sasi\_Rai](https://forum.inductiveautomation.com/u/Sasi_Rai)\
**Post date:** [March 22, 2024, 12:02am UTC](https://forum.inductiveautomation.com/t/iso8061-date-time-format/87605/8 "2024-03-22T00:02:25Z")

</div>

Agreed Transistor. Absolutely. We use DST, so gives that extra bit of work.

Are there any library/function that can handle this automatically? For example, takes the UTC time and desired time zone and return the converted time?

---

<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:** [March 22, 2024, 12:15am UTC](https://forum.inductiveautomation.com/t/iso8061-date-time-format/87605/9 "2024-03-22T00:15:01Z")

</div>

Ignition does it automatically of you let your database base save in UTC. In Perspective Designer you can specify whether the project should convert to gateway timezone or client timezone. I don't know how Vision handles it.

---

<div class="post-metadata">

**Author:** ![Sasi\_Rai](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@Sasi\_Rai](https://forum.inductiveautomation.com/u/Sasi_Rai)\
**Post date:** [March 22, 2024, 12:33am UTC](https://forum.inductiveautomation.com/t/iso8061-date-time-format/87605/10 "2024-03-22T00:33:46Z")

</div>

Thanks PG. I will give that a try as well. Cheers.

---

<div class="post-metadata">

**Author:** ![Sasi\_Rai](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@Sasi\_Rai](https://forum.inductiveautomation.com/u/Sasi_Rai)\
**Post date:** [March 28, 2024, 5:40am UTC](https://forum.inductiveautomation.com/t/iso8061-date-time-format/87605/11 "2024-03-28T05:40:29Z")

</div>

Dear All,

I have been able convert the date/time string into date/time type.

I took Jordan's solution and played around with it till I got what I wanted. Basically declared a new dataset and wrote on it row by row. Everything's sweet.

Now. let's move on to another hurdle. 😃

Thank you everyone. Hope you all have a lovely break!
