# Change Date/Time data type for csv file

**URL:** <https://forum.inductiveautomation.com/t/change-date-time-data-type-for-csv-file/67358>\
**Category:** Ignition\
**Created:** [December 7, 2022, 8:31pm UTC](https://forum.inductiveautomation.com/t/change-date-time-data-type-for-csv-file/67358 "2022-12-07T20:31:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [December 7, 2022, 8:31pm UTC](https://forum.inductiveautomation.com/t/change-date-time-data-type-for-csv-file/67358/1 "2022-12-07T20:31:58Z")

</div>

I am running ignition edge and once a day I am creating a csv file with floating point values coming from the tag historian. I have everything working perfect except my date is being shown as a [u'] type instead of just a string which I want it to be.

Here is a screenshot of the csv file and also the script I have to create the file:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/e/3ea87822b0b4168319d514ad00652f22697f5e21.png)

Here is my script which creates the csv file:

```auto
def create_analogin_csv():
	"""Create analog input csv file with values from past 24 hours
	
	Params:
		none
	
	Returns:
		none
	"""

	#establish logger
	logger = system.util.getLogger("AI CSV file")

	#dynamically create list of analog input tag paths including filter to only look at UDT instance tags
	path = '[PLC]AnalogInputs'
	fltr = {'tagType': "UdtInstance"}
	tags = system.tag.browse(path,fltr)
	dataTagPaths = [str(tag['fullPath']) + "/InputValue" for tag in tags]

	#create custom header row
	headers = []
	headerTagPaths = [str(tag['fullPath']) + "/DeviceName" for tag in tags]
	  #reads in device names and creates array for header. Inserts DATE/TIME header in first index position
	headers = 'DATE/TIME' + "," 
	
	for header in system.tag.readBlocking(headerTagPaths):
		headers = headers + str(header.value) + ","

	#execute tag history query returning hourly values for last 24 hours
	AIdataset = system.tag.queryTagHistory(paths=dataTagPaths, returnSize=24,
		aggregationMode="LastValue", returnFormat='Wide', columnNames=headers, rangeHours = -24)

	#write data to dataset tag
	AIdatasetTag = '[PLC]AnalogInputCSV'
	system.tag.writeBlocking(AIdatasetTag, AIdataset)
	logger.info("Data written to dataset tag")

	#take resulting dataset and format time and date
	AIdatasetF = system.dataset.formatDates(AIdataset, "MM-dd-yyyy HH:mm")
	
	#format dataset to one decimal place and convert dataset to csv
	outputRows = [headers]
	for row in xrange(AIdatasetF.rowCount):
		# add the date value
		outputRow = [AIdatasetF.getValueAt(row, 0)]
		outputRow = str(outputRow) + ","
		# skip the date column
		for col in xrange(1, AIdatasetF.columnCount):
			outputRow = outputRow + str(round(AIdatasetF.getValueAt(row, col), 1)) + ","
		outputRows.append(outputRow)
	
	csv = "\n".join((row for row in outputRows))
	
	#convert dataset to csv file
	#csv = system.dataset.toCSV(dataset = AIdatasetF, showHeaders = True)

	#define file path and populate file
	filePath = "C:\\DailyCSVFiles\\analogin.csv"
	system.file.writeFile(filePath, csv)

	if system.file.fileExists("C:\\DailyCSVFiles\\analogin.csv"):
		logger.info("File written to csv")
	else:
		logger.info("File does not exist!")

```

---

<div class="post-metadata">

**Author:** ![Ben\_Eklund](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ben_eklund/32/40758_2.png) [@Ben\_Eklund](https://forum.inductiveautomation.com/u/Ben_Eklund)\
**Post date:** [December 9, 2022, 9:48pm UTC](https://forum.inductiveautomation.com/t/change-date-time-data-type-for-csv-file/67358/2 "2022-12-09T21:48:39Z")

</div>

Looks like you're already converting the data to a string, so it would be best to cut off the first three and last three characters if the data is a date here:

> outputRow = str(outputRow) + ",".

---

<div class="post-metadata">

**Author:** ![ShaneH](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@ShaneH](https://forum.inductiveautomation.com/u/ShaneH)\
**Post date:** [December 10, 2022, 6:59pm UTC](https://forum.inductiveautomation.com/t/change-date-time-data-type-for-csv-file/67358/3 "2022-12-10T18:59:32Z")

</div>

It looks like your date is coming through as a list or other iterable object, which is why the str() call for the date is formatting it with square braces, etc. I don't know...

If it is a list, you might try adding an index like the following to pull out the first value:

outputRow = str(outputRow[0]) + ","

HTH.  
-Shane
