Standard timestamps can't be used to build filenames, but sometimes it is useful to have a time indication in a unique file name (logs, data, etc.) This node creates timestamps to be used in filenames, dirs, DB table names, etc. like "D20200310T115905".
[{"id":"2861ce58.aff572","type":"function","z":"a3d794f8.c43c28","name":"filename timestamp","func":"\nDate.prototype.pad2 = function(n) { \n return (n < 10 ? '0' : '') + n;\n}\nDate.prototype.yyyymmdd = function() {\n return this.getFullYear()+this.pad2(this.getMonth() + 1)+this.pad2(this.getDate());\n};\n\nDate.prototype.yyyymmddThhmmss = function() {\n return \"D\"+this.yyyymmdd()+\"T\"+ this.pad2(this.getHours())+ this.pad2(this.getMinutes())+ this.pad2(this.getSeconds());\n};\n\nmsg.payload = new Date().yyyymmddThhmmss();\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":860,"wires":[["2a143ec.06dfdc2"]],"info":"Standard timestamps can't be used to build filenames, but sometimes it is useful to have a time indication in a unique file name (logs, data, etc.)\nThis node creates timestamps to be used in filenames.\n### How it works\nThis node adds 3 new functions to Date()\n * pad2(n) returns like \"03\"\n * yyyymmdd() returns like \"20200310\"\n * yyyymmddThhmmss() returns like \"D20200310T104655\"\n\n### How use it\n**input:** a trigger msg (any)\n\n**output:** msg.payload = timestamp by yyyymmddThhmmss()\n"},{"id":"1969d854.5b72e8","type":"inject","z":"a3d794f8.c43c28","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":860,"wires":[["2861ce58.aff572"]]},{"id":"2a143ec.06dfdc2","type":"debug","z":"a3d794f8.c43c28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":860,"wires":[]}]
Hope this can help you.
Best regards
m.s.