CopyDateToStringMMDDYY

I recently came across this little slightly annoying item, not end of world but the following might make more sense.
The CopyDateToStringMMDDYY command works great but I discovered that if you use it to add the resulting string to a file name when writing a file to say the MicroSD or elsewhere, the result is not you would be expecting. The “/” chr 47 is used to separate the days, months and years and as a file path, that doesn’t work to well…it creates folders instead.
I would suggest changing the “/” chr 47 to “-” chr 45 in the command and then it would not be necessary to add the following workaround:
Result = SetNthCharacter(45, DateString, 2);
Result = SetNthCharacter(45, DateString, 5);

I ran into something similar recently, too. But no only did I want a - instead of a / but I also wanted the (not-built-in) YYYY-MM-DD format: Here’s how I did it:

DateToStringDDMMYYYY(sDateString); // Want YYYY-MM-DD vs: 
//DD/MM/YYYY 
//0123456789

// initialize the date stamp before we overwrite it
sYYYY_MM_DD = "YYYY-MM-DD";
sYYYY_MM_DD[0] = sDateString[6];
sYYYY_MM_DD[1] = sDateString[7];
sYYYY_MM_DD[2] = sDateString[8];
sYYYY_MM_DD[3] = sDateString[9];
sYYYY_MM_DD[4] = '-';
sYYYY_MM_DD[5] = sDateString[3];
sYYYY_MM_DD[6] = sDateString[4];
sYYYY_MM_DD[7] = '-';
sYYYY_MM_DD[8] = sDateString[0];
sYYYY_MM_DD[9] = sDateString[1];

In case that helps!
-Mary

1 Like

That’s a very handy format. I’ve always preferred yyyy-mm-dd for filename building because it forces the files to sort and appear in a logical order in any file manager/explorer. This is what I refer to as the “Japanese” date format. The European date format makes some sense (dd-mm-yyyy), but is still annoying from a file sorting point of view, and the way we write dates here in the US makes no sense whatsoever! (mm-dd-yyyy). Don’t get me started on the subject of Daylight Saving Time! :wink:

Thanks for the code snippet for optoscript. I need to play more with optoscript. Examples are really handy for self-learning.

I do a ton of string manipulation in VB, but just haven’t done much in optoscript.

Well I’m no expert on strings but I have in the past done a number of things including creating a serial driver for the early Krohne Magnetic flow meters.
There is a lot you can do and if your pretty handy on VB with strings, you should not have any problem with OptoScript and string manipulation.
I have even used strings to send and receive data from the original OptoTerminal to an ioController before they developed the OptoMMP driver for the OptoTerminal. It actually worked way better than the driver they built.