dataParse Format in DATE

Posted By: Ger1

dataParse Format in DATE - 06/11/18 04:34

I got a csv history file, where in column A the date/time of the timeseries is stored.

The format of column A is already stored in Windows DATE format (for example 10/01/2018 is stored as 43110). The problem I have is that I don't know what to put in for Format in dataParse.
I tried to use
string Format = "+f,f3,f1,f2,f4,f6,f5";
as according to the manual:

"The DATE format is equivalent to a double / var variable and counts the number of days since 12-31-1899 with a resolution of ~ 1 µsec."

However, this did not work at all (I double-checked using the dataSaveCSV script).

Can anyone advise on how to solve this?
Posted By: Ger1

Re: dataParse Format in DATE - 06/11/18 07:30

By the way, I also tried converting column A from DATE into Unix format and use %t.

dataParse did not work with %t and neither did dataSaveCSV (I get an invalid parameter error).

So far the only way I got it working is by manually converting column A to DD/MM/YYYY and use
string Format = "+%d/%m/%Y,f3,f1,f2,f4,f6,f5";
Posted By: jcl

Re: dataParse Format in DATE - 06/11/18 08:11

dataParse supports %t. So the normal way would be to read all timestamps with %t, and then convert them by script from the Unix time format to the DATE format. You can use this formula:

Date = UnixSeconds/(24.*60.*60.) + 25569.;
Posted By: Ger1

Re: dataParse Format in DATE - 06/11/18 09:11

Thanks jcl.

Just tried it, %t works with dataParse, but dataSaveCSV still returns an invalid parameter error. I used below code:

int Records = dataParse(1,Format,InName);
dataSaveCSV (1,Format,"check.csv");

Also thanks a lot for your hint to converting from the Unix time format to the DATE format.

But could you please advise how that can be achieved?
Doesn't dataParse read from csv and convert to t6 directly?
I have no idea where to do the conversion from Unix to DATE.

Thanks
Posted By: jcl

Re: dataParse Format in DATE - 06/11/18 14:46

After parsing the data, run a loop over all records, read the date from field 0, convert it to DATE, and write it back. Then save the dataset. For saving in CSV format, use a normal date format string like "%Y-%m-%d", not "%t" which is specific to Zorro and not supported by the Windows date format.
Posted By: Ger1

Re: dataParse Format in DATE - 06/11/18 22:46

Thanks a lot.

Below code worked:

string Format = "+%t,f3,f1,f2,f4,f6,f5";

function main()
{
int Records = dataParse(1,Format,InName);
printf("n%d lines read",Records);
dataSort(1);
int i;
for(i=0; i<Records; i++)
dataSet(1,i,0,(dataVar(1,i,0) - 25569.)*(24.*60.*60.));

dataSaveCSV (1,"%d/%m/%Y,f3,f1,f2,f4,f6,f5","check.csv");
if(Records) dataSave(1,OutName);
}
© 2024 lite-C Forums