# Data Source Scripting

**URL:** <https://forum.inductiveautomation.com/t/data-source-scripting/18453>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [June 13, 2018, 5:35pm UTC](https://forum.inductiveautomation.com/t/data-source-scripting/18453 "2018-06-13T17:35:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![harryzhou4498](https://avatars.discourse-cdn.com/v4/letter/h/71c47a/32.png) [@harryzhou4498](https://forum.inductiveautomation.com/u/harryzhou4498)\
**Post date:** [June 13, 2018, 5:35pm UTC](https://forum.inductiveautomation.com/t/data-source-scripting/18453/1 "2018-06-13T17:35:28Z")

</div>

I’m trying to run a script that will filter out the motor speed that doesn’t specifically have the timestamp of 9 am on every day and show two columns of the date at 9 am and the motor speed at that time for multiple days. This is my code so far.

```auto
	header = ['Mtr Spd','Date']
	filteredDataset = []
	rawDataset = data['motor speed_1'].getCoreResults()
	
	for row in range(rawDataset.rowCount):
		if (system.date.getHour24(data['Date'])) == 9:
			specificVal = rawDataset.getvalueAt(row,'mtr spd')
			specificTime = rawDataset.getvalueAt(row,'t_stamp')
			filteredDataset.append([specificTime, specificVal])
					
	filteredDataset = system.dataset.toDataSet(header,filteredDataset)
	
	data['updated Data'] = filteredDataset

```

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/7e0c832f17403b24ae9042b3f71ce9b87dae3bee.png)

The issue right now is that on line 7, the function system.date.getHour doesn’t work because data[‘t\_stamp’] is not a correct date entry. However, I’m not sure what else I can use to keep track of the time. StartDate/endDate work but they don’t do what I specifically want. I’m also not sure if the query, motor speed\_1, that I’m trying to extract data from has enough data to draw from since I only have a few results showing up for that query in the window.

---

<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:** [June 13, 2018, 5:50pm UTC](https://forum.inductiveautomation.com/t/data-source-scripting/18453/2 "2018-06-13T17:50:11Z")

</div>

Please don’t use screenshots of code. Paste the code itself into your post, with a line of just ``` above it, and another triple-backtick below it.

Anyways, you need to extract the t\_stamp from your raw dataset and check the hour on it, not on anything from data. Something like this:

```auto
for row in range(rawDataset.rowCount):
    specificTime = rawDataset.getValueAt(row, 't_stamp')
    if specificTime and specificTime.hour == 9:
        .......

```

---

<div class="post-metadata">

**Author:** ![harryzhou4498](https://avatars.discourse-cdn.com/v4/letter/h/71c47a/32.png) [@harryzhou4498](https://forum.inductiveautomation.com/u/harryzhou4498)\
**Post date:** [June 13, 2018, 5:57pm UTC](https://forum.inductiveautomation.com/t/data-source-scripting/18453/3 "2018-06-13T17:57:47Z")

</div>

getting this error for specifictime.hour:  
WARN: Traceback (most recent call last):  
File “function:updateData”, line 9, in updateData  
AttributeError: ‘java.sql.Timestamp’ object has no attribute ‘hour’

---

<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:** [June 13, 2018, 6:29pm UTC](https://forum.inductiveautomation.com/t/data-source-scripting/18453/4 "2018-06-13T18:29:32Z")

</div>

Sorry. Use `.hours`. See the Javadoc for [java.util.Date](https://docs.oracle.com/javase/8/docs/api/java/util/Date.html), which java.sql.Timestamp extends.
