# Parsing date from perspective table

**URL:** <https://forum.inductiveautomation.com/t/parsing-date-from-perspective-table/85432>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [February 8, 2024, 1:43pm UTC](https://forum.inductiveautomation.com/t/parsing-date-from-perspective-table/85432 "2024-02-08T13:43:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leigh.shannan](https://avatars.discourse-cdn.com/v4/letter/l/b2d939/32.png) [@Leigh.shannan](https://forum.inductiveautomation.com/u/Leigh.shannan)\
**Post date:** [February 8, 2024, 1:43pm UTC](https://forum.inductiveautomation.com/t/parsing-date-from-perspective-table/85432/1 "2024-02-08T13:43:17Z")

</div>

Hi,

I have a perspective table which is populated by a named query. The results of the query are then ran though a transform script, the output of which is a JSON dataset.

I have an "onRowClick" event script in which I would like to take some of the values and execute another query.

An example of the event created when clicking a row is below:

```auto
{"row":5,"rowIndex":5,"value":{"event_id":84,"NAME":" ************","DATE":"Wed Feb 21 2024 00:00:00 GMT+0000 (Greenwich Mean Time)","HOURS":"08:00-16:00","REQUESTER COMMENT":"","APPROVED?":2,"APPROVER COMMENT":""}}

```

The date is returned as a string and I am struggling to parse it. I have tried some different string formats but none are working:

```auto
system.date.parse(eventDate,"ddd MMM DD YYYY HH:mm:ss z", "en-GB")

```

```auto
system.date.parse(eventDate,"E MMM dd yyyy HH:mm:ss z", "en-GB")

```

Can anyone point me in the right direction with this?

Thanks,  
Leigh

---

<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:** [February 8, 2024, 1:52pm UTC](https://forum.inductiveautomation.com/t/parsing-date-from-perspective-table/85432/2 "2024-02-08T13:52:28Z")

</div>

Don't manipulate dates as strings. Keep them as dates, and set your component to **render** them correctly. Then you don't have to parse them. (You should only ever parse **user-supplied** date strings.)

---

<div class="post-metadata">

**Author:** ![Leigh.shannan](https://avatars.discourse-cdn.com/v4/letter/l/b2d939/32.png) [@Leigh.shannan](https://forum.inductiveautomation.com/u/Leigh.shannan)\
**Post date:** [February 8, 2024, 3:04pm UTC](https://forum.inductiveautomation.com/t/parsing-date-from-perspective-table/85432/3 "2024-02-08T15:04:43Z")

</div>

Thanks for your reply.

If I have changed dates to strings at any point it has been unintentional and I don't know where that would have happened.

The named query returns a date from the database. The transform script is only meant to add styling to the table. I haven't explicitly done anything to alter values.

```auto
def transform(self, value, quality, timestamp):
	output_json = []
	    
	style_red = {"backgroundColor": "LightCoral"}
	style_green = {"backgroundColor": "LightGreen"}
	style_yellow = {"backgroundColor": "PaleGoldenRod"}
	
	for row in range(value.getRowCount()):
		row_object = {}
					
		for col in value.getColumnNames():    
			cell_object = {}
			cell_style = {}
			# Add a key/value pair for the cell
			cell_object['value']=value.getValueAt(row, col)
			
			# Select the style
			if col == 'APPROVED?':
				status = value.getValueAt(row, col)
				if status == 0:
					cell_style = style_red
				elif status == 1:
					cell_style = style_green
				elif status == 2:
					cell_style = style_yellow
			
			cell_object['style']=cell_style
			
			#Add the cell object to the row object
			row_object[col]=cell_object
		
		#Add the row_object to the output					
		output_json.append(row_object)	
		
	return output_json

```

The dates in the table format as expected.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/6/56bdbbfdf66464fe3544303da6b0ce4b69bae451.png)

It is only when I work with the data from the onRowClick event that the date seems to change to a string. Should I be doing a **system.util.jsonDecode** first before working with the data?

---

<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:** [February 8, 2024, 3:15pm UTC](https://forum.inductiveautomation.com/t/parsing-date-from-perspective-table/85432/4 "2024-02-08T15:15:06Z")

</div>

I have no idea why the date would become a string, but did you configure the `columns` property on the table ? Maybe, somehow, this has an effect on the datatype of the variable you get from your onRowClick script ?  
Can we see that script, by the way ?

Also, if you're gonna use json, you might as well change the query binding's return format to json. Should make the transform simpler.

edit: I just tried, with mssql and a datetime, I get a long with the timestamp in the `onRowClick` event.
