cancel
Showing results for 
Search instead for 
Did you mean: 

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

yes1819
New Contributor III

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

 

yes1819_0-1702417780423.png

 

1 ACCEPTED SOLUTION

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"})

yes1819_0-1702418960336.png

yes1819_1-1702419173201.png

 

View solution in original post

4 REPLIES 4

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"})

 


Diane Miller

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"})

yes1819_0-1702418960336.png

yes1819_1-1702419173201.png

 

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.


Diane Miller

yes1819
New Contributor III

Thank you SO much Miller.

For future reference, I've used

"file_name_"+Date.now().toLocaleDateString({timeZone:"PST", format:"yyyy-MM-dd"})+".csv"

and it saved the csv file on S3 with Date only. Thank you 🙂