cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Create a file path with a date in File Writer snap

SnapWizard
New Contributor III

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?

2 REPLIES 2

koryknick
Employee
Employee

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.

SnapWizard
New Contributor III

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.
image