Add date to 'save to file' node


i want that the ‘save to file’ node uses the current date in the filename, so i added function in which i add ‘date’ property to the msg, and then in the save node i wrote: “{{}}.csv”, but the node is not reading the date property and it stores the file with this name: “{{}}.csv”.
i hope that you can help.



You cannot use the {{ }} syntax in the file name field. You need to generate the filename you want and pass it into the node as msg.filename - as described in the info sidebar of the File node.

1 Like


It would be helpful if you provided the code you used in the function…



Thank you.
that’s the code i wrote in the function:

var d = new Date();
var t = d.getTime();
var year = d.getFullYear();
var month = d.getMonth()+1; 
if(month.toString().length == 1) {
var month = '0'+month;
var day = d.getDate();
var hour  = d.getHours(); = t;
msg.filename = "measurements/"+year+month+day+".csv";
return msg;

and it is working well.

1 Like