Creating a string with a date for use as a file name

I am trying to create a string name that will be used as a unique identifier for a bunch of individual .csv files.

Goal: 08302017054659.csv
The format is basically month,day,year,hour,minute,second

I am aware of the Time$ function, but this in itself has parses in the string such as “/”, which cannot be used for a file name.

I am able to individually withdraw the day and month using built in functions, there is trouble with the others.

Thanks!

Hello, @nickTriPhase1!

You can extract substrings from the Time$ variable using the below format (note, the variable names you choose do not have to match what I have listed below):

T$ = Time$
year$ = T$(7 To 10)
mon$ = T$(4 To 5)
date$ = T$(1 To 2)
hour$ = T$(12 To 13)
min$ = T$(15 To 16)
sec$ = T$(18 To 19)
PRINT year$ + mon$ + date$ + hour$ + min$ + sec$

The number printed would follow the format that you are looking for. A great example that uses this feature is on our developer website located at https://developer.websupport.ewon.biz/content/planner-entry-dynamic-filename that I’ve included below. The example script uses this method to extract substrings from the Time$ variable. It uses the custom variable A$ to create a filename.

MyAction:
    T$=Time$
    A$="/usr/MyData/Data"+T$(7 To 10)+"-"+T$(4 To 5)+"-"+T$(1 To 2)+".csv"
    PUTFTP A$,"[$dtHL $ftT $st_d1 $et_s0 $tnTestTag]"
END

Please let me know if this answers your question!

Best regards,
Ashley

1 Like

This answers my question. I didn’t know there was a way to parse Strings here, thanks!

1 Like

@nickTriPhase1, You are very welcome! Additionally, if you are running updated firmware on the Flexy, you can also use the below function to simplify things a little bit.

//This function will format the current time string as a straight integer. 
//For example: 30/08/2017 16:02:48 will convert to: 083020171602748
FUNCTION formatCurrentTimeString$
    t$ = TIME$
    $formatCurrentTimeString$ = t$(4 TO 5) + t$(1 TO 2) + t$(7 TO 10) + t$(12 TO 13) + t$(15 TO 16) + t$(18 TO 19)
ENDFN

I hope this helps!

Best regards,
Ashley

1 Like

Ashley,

I already set out and created one for my needs :grinning:

1 Like