How to use the "moment" node?

Hi,

I am looking for some examples to get a readable datetime format out of the "moment" node.
I need something I can passthrough to my MS-SQL Server - the datetime format is defined like that:
2019-12-22 20:27:39.012

All I get from the moment node is: 2019-12-22T21:27:39.167Z
The format is wrong and its giving my the wrong time zone :frowning:

Do I really have to parse this output sign by sign and re-format it ? or is there any functionality I could use ?

BR
Gawan

...the output format ist documented here, as already linked in the node description: https://momentjs.com/docs/#/displaying/format/

My guess is, that what you want is something like "YYYY-MM-DD HH.mm.ss.SS" in the output format section of the node.
Just feed a suitable time object into it via the payload, i.e. create from a function node with "msg.payload = new Date().toISOString();".

Here's a mini flow:

[{"id":"48703c49.cf7214","type":"function","z":"90f78b.543da878","name":"timestamp","func":"msg.payload = new Date().toISOString();\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":420,"wires":[["3e4ccaf8.9d2526"]]},{"id":"3e4ccaf8.9d2526","type":"moment","z":"90f78b.543da878","name":"dd DD.MM.YY - HH:mm","topic":"date","input":"payload","inputType":"msg","inTz":"Europe/Berlin","adjAmount":0,"adjType":"days","adjDir":"add","format":"dd DD.MM.YY - HH:mm","locale":"DE","output":"payload","outputType":"msg","outTz":"Europe/Berlin","x":590,"y":480,"wires":[["47c2ee55.7a954"]]}]
1 Like

I believe the node will allow a raw timestamp value to be input, there is no point converting it to a string for the node then to convert it back to a timestamp in order to format it as required. So you can just use msg.payload = new Date()

1 Like

thats exactly what I need !

YYYY-MM-DD HH:mm:ss.sss

perfect, thanks a lot guys !!