Mustache date expansion bug?

I am rendering a template with mustache formatting.

format_date('{{{payload.0.OrderDate}}}')

payload.0.OrderDate comes from a database, format: 2024-01-11 11:59:32.903

However, after rendering the template, this is the result:
format_date('Tue Jan 02 2024 10:58:54 GMT+0000 (Coordinated Universal Time)')

Why this is happening ?

I would say that the date returned is a date object you can use Date.prototype.toLocaleString() - JavaScript | MDN
to format to local timedate string prior to template or see also in link.
example

[{"id":"eec5903c8672f509","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":80,"y":3380,"wires":[["0447eb90760c8d16"]]},{"id":"0447eb90760c8d16","type":"function","z":"d1395164b4eec73e","name":"function 151","func":"msg.payload = new Date(msg.payload)\nmsg.format_date = msg.payload.toLocaleString()\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":210,"y":3440,"wires":[["31f66720c8809269","1d84d16f6e9368c6"]]},{"id":"31f66720c8809269","type":"template","z":"d1395164b4eec73e","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"This is the payload: {{{payload}}}\nThis is the time: {{{format_date}}}","output":"str","x":400,"y":3480,"wires":[["1d84d16f6e9368c6"]]},{"id":"1d84d16f6e9368c6","type":"debug","z":"d1395164b4eec73e","name":"debug 2465","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":3400,"wires":[]}]

The value will be a date object.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.