# Convert string column to Datetime

**URL:** <https://forum.inductiveautomation.com/t/convert-string-column-to-datetime/23013>\
**Category:** Ignition\
**Created:** [March 2, 2019, 11:55am UTC](https://forum.inductiveautomation.com/t/convert-string-column-to-datetime/23013 "2019-03-02T11:55:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamerplc](https://avatars.discourse-cdn.com/v4/letter/t/d78d45/32.png) [@tamerplc](https://forum.inductiveautomation.com/u/tamerplc)\
**Post date:** [March 2, 2019, 11:55am UTC](https://forum.inductiveautomation.com/t/convert-string-column-to-datetime/23013/1 "2019-03-02T11:55:44Z")

</div>

I am retrieving certain data from 3rd party scada system using below query and need to added data set results to charts in ignition . The problem is the datetime column is coming as string not as data time format as per below snapshot . How can i convert it to Dattime format? .

```auto
SELECT DateTime , Value
FROM History 
WHERE TagName IN ('MWDashBoardIOs.C1_Co2')
AND wwRetrievalMode = 'Cyclic'
AND wwResolution = 86400000
AND wwQualityRule = 'Extended'
AND wwVersion = 'Latest'
AND DateTime >= '{Root Container.Popup Calendar 1.formattedDate}'
AND DateTime < '{Root Container.Popup Calendar.formattedDate}'

```

 ![12](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6eb4a3075a680968dbb355b96f7739b542611e4a.jpeg)

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [March 2, 2019, 4:06pm UTC](https://forum.inductiveautomation.com/t/convert-string-column-to-datetime/23013/2 "2019-03-02T16:06:14Z")

</div>

You can iterate through the rows of that dataset converting date strings to dates something like this:

```python
# Create sample dataset with date strings.
headers = ['DateTime', 'Value']
data = [['2019-02-27 22:57:00.0000000',72181]]
data.append(['2019-02-28 22:57:00.0000000', 73365])
data.append(['2019-03-01 22:57:00.0000000', 73905])
dataset = system.dataset.toDataSet(headers, data)
# Convert date strings in first column to dates in new dataset.
newData = []
print 'Original rows:'
for row in range(dataset.rowCount):
	print type(dataset.getValueAt(row, 0)), dataset.getValueAt(row, 0), dataset.getValueAt(row, 1)
	# Make new row with date string converted to date.
	newData.append([system.date.parse(dataset.getValueAt(row, 0)), dataset.getValueAt(row, 1)])
newDataset = system.dataset.toDataSet(headers, newData)
# Confirm types are dates.
print 'Converted rows:'
for row in range(newDataset.rowCount):
	print type(newDataset.getValueAt(row, 0)), newDataset.getValueAt(row, 0), newDataset.getValueAt(row, 1)
# Write/assign newDataset to chart data.

```

Which gives this output in script console:

```auto
Original rows:
<type 'unicode'> 2019-02-27 22:57:00.0000000 72181
<type 'unicode'> 2019-02-28 22:57:00.0000000 73365
<type 'unicode'> 2019-03-01 22:57:00.0000000 73905
Converted rows:
<type 'java.util.Date'> Wed Feb 27 22:57:00 PST 2019 72181
<type 'java.util.Date'> Thu Feb 28 22:57:00 PST 2019 73365
<type 'java.util.Date'> Fri Mar 01 22:57:00 PST 2019 73905

```

---

<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:** [March 2, 2019, 4:40pm UTC](https://forum.inductiveautomation.com/t/convert-string-column-to-datetime/23013/3 "2019-03-02T16:40:33Z")

</div>

You might find the [view()](https://www.automation-pros.com/simaids/doc/expression.view.html) expression function (from the free [Simulation Aids](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids) module) a bit more convenient here. Assuming you move the original binding to a custom property called `RawData`, the expression for the `data` binding would be:

```auto
view("Select system.date.parse(DateTime) As DateTime, Value",
  {Root Container.Table.RawData})

```
