# Mustache date expansion bug?

**URL:** <https://discourse.nodered.org/t/mustache-date-expansion-bug/84590>\
**Category:** General\
**Created:** [16 January 2024 06:42 UTC](https://discourse.nodered.org/t/mustache-date-expansion-bug/84590 "2024-01-16T06:42:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [16 January 2024 06:42 UTC](https://discourse.nodered.org/t/mustache-date-expansion-bug/84590/1 "2024-01-16T06:42:46Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [16 January 2024 08:05 UTC](https://discourse.nodered.org/t/mustache-date-expansion-bug/84590/2 "2024-01-16T08:05:16Z")

</div>

I would say that the date returned is a date object you can use [Date.prototype.toLocaleString() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)  
to format to local timedate string prior to template or see also in link.  
example

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 January 2024 08:05 UTC](https://discourse.nodered.org/t/mustache-date-expansion-bug/84590/3 "2024-01-16T08:05:29Z")

</div>

> [@bakman2](#):
>
> Why this is happening

The value will be a date object.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 March 2024 08:06 UTC](https://discourse.nodered.org/t/mustache-date-expansion-bug/84590/4 "2024-03-16T08:06:28Z")

</div>

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