Create a file path with a date in File Writer snap

I have a pipeline that generates an output file that I would like to save in S3 with a file path of
YYYY/MM/dd/file_name… e.g. S3://bucket/2023/08/09/file_name.csv. When I do this:
“s3:///bucket/”+Date.now().getFullYear()+“/”+Date.now().getMonth()+“/”+Date.now().getDate()+“/fil_name.csv”
It generates a path of 2023/8/9, How can I programmatically determine when to pad it with a ‘0’ for single digit months and days without including this data in the document being saved?

Personally I like pipe.startTime over Date.now() since it is consistent throughout your pipeline execution and correlates to your pipeline execution time in the Dashboard - try this:
"s3:///bucket/" + pipe.startTime.toLocaleDateString( { format : "yyyy/MM/dd" } ) + "/filename.csv"
This should yield what you’re looking for.

1 Like

I placed the logic in the csv formatter and stored it as a variable and used the variable as part of the path used by the writer snap. This worked.