Add date to 'save to file' node

#1

Hello,
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: “{{msg.date}}.csv”, but the node is not reading the date property and it stores the file with this name: “{{msg.date}}.csv”.
i hope that you can help.

0 Likes

#2

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

#3

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

0 Likes

#4

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();
msg.date = t;
msg.filename = "measurements/"+year+month+day+".csv";
return msg;

and it is working well.

1 Like