# Help - MQTT JSON reformat date field prior to insert into mySQL

**URL:** <https://discourse.nodered.org/t/help-mqtt-json-reformat-date-field-prior-to-insert-into-mysql/65815>\
**Category:** General\
**Tags:** function-node\
**Created:** [30 July 2022 15:38 UTC](https://discourse.nodered.org/t/help-mqtt-json-reformat-date-field-prior-to-insert-into-mysql/65815 "2022-07-30T15:38:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Duncan-Hill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/duncan-hill/32/65440_2.png) [@Duncan-Hill](https://discourse.nodered.org/u/Duncan-Hill)\
**Post date:** [30 July 2022 15:38 UTC](https://discourse.nodered.org/t/help-mqtt-json-reformat-date-field-prior-to-insert-into-mysql/65815/1 "2022-07-30T15:38:26Z")

</div>

I have an MQTT subscription which outputs parsed JSON into a function that reformats and outputs a message:

- MQTT \> Function 'Reformat Message' \> Function 'Create SQL' \> mySQL connection

The challenge I'm facing is reformatting the JSON date into a mySQL datetime value, I've found the moments formats which is correctly formatting the date but I'm struggling on how to either update the date value or join the data:

- MQTT \> Function Moments \> Function 'Reformat Message' \> Function 'Create SQL' \> mySQL connection \*\*\* The moments function only outputs the date and not the original MQTT data

- MQTT \> Function 'Reformat Message' \> JOIN \>Function 'Create SQL' \> mySQL connection  
\> Function Moments --------------\> \*\*\* The join is not inserting correctly formatted data

The only way I have managed to get this to work is as follows:

- MQTT \> Function 'Reformat Message' \> JOIN \>Function 'Create SQL' \> mySQL connection  
\> Function Moments \> GLOBAL value \*\*\* The Create SQL function then uses the GLOBAL value

Is there a better way to achieve what I need to do, reformat date, my concern with my working solution relates to when the GLOBAL value is set, will this be set before the Create SQL is run?

---

<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:** [30 July 2022 15:43 UTC](https://discourse.nodered.org/t/help-mqtt-json-reformat-date-field-prior-to-insert-into-mysql/65815/2 "2022-07-30T15:43:27Z")

</div>

you could probably reformat the data with a JSONata expression in a change node, or JS in a function node, i doubt you would need a join. It would help if you supplied an example (text not an image) of the incoming data, and how you wanted it formatted.

---

<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:** [28 September 2022 15:43 UTC](https://discourse.nodered.org/t/help-mqtt-json-reformat-date-field-prior-to-insert-into-mysql/65815/3 "2022-09-28T15:43:52Z")

</div>

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