12-12-2023 01:52 PM
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
Solved! Go to Solution.
12-12-2023 02:13 PM
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"})
12-12-2023 02:02 PM
I would use Date.now() with .toLocaleDateString and specify the date format you want such as:
Date.now().toLocaleDateString({"format":"yyyy-mm-dd"})
12-12-2023 02:13 PM
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"})
12-12-2023 02:18 PM
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.
12-12-2023 02:28 PM
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 🙂