FileReadDateTime renders date incorrectly

 

Hi there,

Your assistance is appreciated, thanks.

I have a csv file that looks like this:

20140103 14:30:00
20140106 10:00:00
20140106 17:30:00

FileReadDateTime() "Reads from the file of CSV type a string of one of the formats: "YYYY.MM.DD HH:MI:SS", "YYYY.MM.DD" or "HH:MI:SS" - and converts it into a value of datetime type."

My code reads the first line and converts it to "2014.07.08 14:30:00" instead of "2014.01.03 14:30:00".

Here is the code:

input string fileName="eventdates.csv";

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   getNewsTime();
  }
//+------------------------------------------------------------------+
void getNewsTime()
  {  
   ResetLastError();
   int fileHandle=FileOpen(fileName,FILE_READ|FILE_CSV);
   if(fileHandle!=INVALID_HANDLE)
     {
      PrintFormat("%s file is open for reading",fileName);
      Print(FileReadDatetime(fileHandle));
      
      //--- close the file
      FileClose(fileHandle);
     }
   else
     {
      PrintFormat("Failed to open %s file, Error code = %d",fileName,GetLastError());
     }
  }// end getNewsTime

Can you please advise?

Thanks,

Brad.

 

I did this and think it'll work..

 token=FileReadString(fileHandle);
 year=StringSubstr(token,0,4);
 month=StringSubstr(token,4,2);
 day=StringSubstr(token,6,2);
 time=StringSubstr(token,9,5);
 newsTime=StrToTime(StringConcatenate(year,".",month,".",day," ",time));
 
brad: I have a csv file that looks like this:
20140103 14:30:00
20140106 10:00:00
20140106 17:30:00

FileReadDateTime() "Reads from the file of CSV type a string of one of the formats: "YYYY.MM.DD HH:MI:SS"

Since it wants YYYY<DOT>MM<DOT>DD and you are giving it 20140103 (no dots,) why would do you expect it to work?
 
Thanks.
Reason: