Forum Discussion

yes1819's avatar
yes1819
New Contributor III
2 years ago
Solved

S3 file upload with TODAY'S date in the file name

Hi,

I'm trying to add today's date in the file name when I load CSV file on S3 bucket.

I know there is Date.now() , but this gives date with local tiem.

What's the best way to add local DATE only (today's local date) (NOT THE TIME)?

Thank you

 

 

  • Thank you so much Miller.

    Your code was working ok, but it saved file with some weird date. 

    In the screenshot, the first file is with your code, and saved as 2023-04-12 instead of 2023-12-12

    Below 2 files are saved with Date.now()  and their date is ok.

    Do you think you can figure out why it saved the file as 2023-04-12?

    The last screenshot is the new snap that I used your code.

    Thank you so much!

    Date.now().toLocaleDateString({"format":"yyyy-mm-dd"})

     

4 Replies

  • dmiller's avatar
    dmiller
    Former Employee

    I would use Date.now() with .toLocaleDateString and specify the date format you want such as:

    Date.now().toLocaleDateString({"format":"yyyy-mm-dd"})

     

    • yes1819's avatar
      yes1819
      New Contributor III

      Thank you so much Miller.

      Your code was working ok, but it saved file with some weird date. 

      In the screenshot, the first file is with your code, and saved as 2023-04-12 instead of 2023-12-12

      Below 2 files are saved with Date.now()  and their date is ok.

      Do you think you can figure out why it saved the file as 2023-04-12?

      The last screenshot is the new snap that I used your code.

      Thank you so much!

      Date.now().toLocaleDateString({"format":"yyyy-mm-dd"})

       

      • dmiller's avatar
        dmiller
        Former Employee

        Sorry, that was because that was the format I specified: "yyyy-mm-dd"

        If you want standard US date formatting, change the format value to "mm/dd/yyyy"

        See the Parsing Date example in the documentation for other date format examples.