Forum Discussion

FalleurJ's avatar
FalleurJ
New Contributor
7 years ago

Time stamp on an end of a file

Hello,

I am trying to figure out the time stamp features, and I can’t seem to get it to work.

I have on my file writer: “XXXXXXX_” + Date.now() + .txt

But that doesn’t work, Can someone inform me on what I need to do to correct this and get this to work? I want to have YYYYMMDDHHMMSS in the time stamp.

8 Replies

  • If you change the expression to this then you’ll get close. [note: I quoted the .txt]

    Expression: “XXXXXXX_” + Date.now() + “.txt”
    Result: XXXXX_2018-11-28T18:10:54.456Z.txt

    You could further format the date by doing.

    Expression: “XXXXXXX_” + Date.now().toLocaleDateTimeString({“format”:“yyyyMMddHHmmss”}) + “.txt”
    Result: XXXXX_20181128181830.txt

    Here is more documentation on the toLocaleDateTimeString.

    • FalleurJ's avatar
      FalleurJ
      New Contributor

      Okay, I have tried both ways you have and it is still messing up. to give further explaination, my file name is a directory path to our FTP server and then the name. so for example. it is something like this…

      /home/edi/BS/Trade/P41/out/“filename” + Date.now().toLocaleDateTimeString({“format”:“yyyyMMddHHmmss”}) + “.txt”

      An on the server it is literally posting that as the name ^^

  • smakkena's avatar
    smakkena
    New Contributor II

    I am guessing you do NOT have the expression toggle on for the File name property…causing it to treat the value as literal text.

    • FalleurJ's avatar
      FalleurJ
      New Contributor

      That makes it fail when I have it as an expression. Since it is on a server could that be an issue.

      • smakkena's avatar
        smakkena
        New Contributor II

        You need to double quote the “static text” part of your expression.

  • You’ll want to do something like this as the expression, but fill it in with the specifics of the hostname. As @smakkena points out, the sftp part needs to be surrounded in quotes. That creates a string that you concatenate with the Date experssion. Then you concatenate the “.txt” string on to the end.

    "sftp://my.ftp.com/home/edi/BS/Trade/P41/out/filename" + Date.now().toLocaleDateTimeString({"format":"yyyyMMddHHmmss"}) + ".txt"

    EDIT A colleague pointed out that the double quotes were being replaced by angled quotes by the community editor, which may also be impacting the parsing of the expression. You may need to correct that in the snap’s expression too.