How include date and time in a csv file handle

 

Hi All,

I hope somebody out there can help me.

I want to add the date and time to my csv file handle, so that my filename will be something like 2022.12.08 10:40 Result.csv

If I do this:-

string _filename=TimeToStr(TimeLocal(),TIME_DATE|TIME_MINUTES)+" Result.csv"; 
Alert("_filetname is ",_filename); 

My alert panel returns  2022.12.08 10:40 Result.csv  which is what I expected.

However if I do this:-

   _myhandle=FileOpen(_filename,FILE_CSV|FILE_READ|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE,","); 

the file isn't generated. If I don't try to include the date and time, all works perfectly well.

I've tried umpteen combinations, all to no avail.

Please help ...

 
Graham from Brisbane: My alert panel returns  2022.12.08 10:40 Result.csv  which is what I expected.

A colon terminates the device name (C:) thus your file name is invalid.

 
William Roeder #:

A colon terminates the device name (C:) thus your file name is invalid.

Sorry Mr. R, I'm not sure what you mean ....

If I change to _filename = "Result.csv", leaving out the date and time, everything works perfectly well.

 
Graham from Brisbane #:Sorry Mr. R, I'm not sure what you mean .... If I change to _filename = "Result.csv", leaving out the date and time, everything works perfectly well.

You can't have the character ":" in a file name. It is invalid. It is used for drive name (e.g. "C:\").

So you will have to use a different format for the time (e.g. "h" instead of ":", "20h34" instead of "20:34").

So once you have the Date and Time string, replace the ":" with "h".

string _datetime = TimeToString( TimeLocal() ); 
StringReplace( _datetime, ":", "h" );
string _filename = _datetime + " Result.csv"; 
 
Fernando Carreiro #:

You can't have the character ":" in a file name. It is invalid. It is used for drive name (e.g. "C:\").

So you will have to use a different format for the time (e.g. "h" instead of ":", "20h34" instead of "20:34").

So once you have the Date and Time string, replace the ":" with "h".

Ahhhh... Thank you very much. Now I understand perfectly. Fantastic .....   :)
 
Graham from Brisbane #: Ahhhh... Thank you very much. Now I understand perfectly. Fantastic .....   :)
You are welcome!
 
Fernando Carreiro #: e.g. "h" instead of ":", "20h34" instead of "20:34"
Or replace the colon with a semicolon.
 
William Roeder #: Or replace the colon with a semicolon.

Emphasis on "e.g." — for example. The OP can use what he wants.