# Help| how to add timestamp into csv file

**URL:** <https://discourse.nodered.org/t/help-how-to-add-timestamp-into-csv-file/48973>\
**Category:** General\
**Created:** [27 July 2021 16:59 UTC](https://discourse.nodered.org/t/help-how-to-add-timestamp-into-csv-file/48973 "2021-07-27T16:59:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![puteramelaka](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/puteramelaka/32/45520_2.png) [@puteramelaka](https://discourse.nodered.org/u/puteramelaka)\
**Post date:** [27 July 2021 16:59 UTC](https://discourse.nodered.org/t/help-how-to-add-timestamp-into-csv-file/48973/1 "2021-07-27T16:59:20Z")

</div>

Hello all, recently i have manage to split data from MQTT and saved as CSV ,thanks to forum member that really kind and helpfull.

For now i want to do is **add timestamp** (if im not mistaken) which **add date and time** of data taken.the date and time is already stated in the MQTT and Node-red , how to refer it and add it into csv file..

i have read some example and tried but fail, the result as below:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/50bc99cc0c5e80943267d4967944bd1e966c69b8.png)

the yellow highlight is the data and time im trying to add into csv and the properties is the code.. in the csv it appear the random number not value of axis

what i expected it to be as below

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/3/136ea5c179485a6cdcebd8219ef3dbd32e1e0f0b.png)

---

<div class="post-metadata">

**Author:** ![puteramelaka](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/puteramelaka/32/45520_2.png) [@puteramelaka](https://discourse.nodered.org/u/puteramelaka)\
**Post date:** [27 July 2021 17:02 UTC](https://discourse.nodered.org/t/help-how-to-add-timestamp-into-csv-file/48973/2 "2021-07-27T17:02:48Z")

</div>

the current view of node-red flow

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/9/699ccebf715d15f871bad453fe5316e84847e9f3.png)

---

<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:** [27 July 2021 17:20 UTC](https://discourse.nodered.org/t/help-how-to-add-timestamp-into-csv-file/48973/3 "2021-07-27T17:20:32Z")

</div>

You should be able to add to the string in the change nodes.  
Try using $moment(), you can set the time zone if you wish to.  
JSONata expression

```auto
"X-AXIS," & $$.payload.`X-AXIS` & $moment().tz("Asia/Tokyo").format(",DD/MM/YYYY,h:mm:ss a")

```

[https://momentjs.com/timezone/](https://momentjs.com/timezone/)

---

<div class="post-metadata">

**Author:** ![puteramelaka](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/puteramelaka/32/45520_2.png) [@puteramelaka](https://discourse.nodered.org/u/puteramelaka)\
**Post date:** [27 July 2021 17:37 UTC](https://discourse.nodered.org/t/help-how-to-add-timestamp-into-csv-file/48973/4 "2021-07-27T17:37:42Z")

</div>

thanks , i will try it and post the result here

---

<div class="post-metadata">

**Author:** ![puteramelaka](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/puteramelaka/32/45520_2.png) [@puteramelaka](https://discourse.nodered.org/u/puteramelaka)\
**Post date:** [27 July 2021 17:51 UTC](https://discourse.nodered.org/t/help-how-to-add-timestamp-into-csv-file/48973/5 "2021-07-27T17:51:27Z")

</div>

> [@E1cid](#):
>
> `"X-AXIS," & $.payload.` X-AXIS ` & $moment().tz("Asia/Tokyo").format(",DD/MM/YYYY,h:mm:ss a")`

since i have 3 change node for 3 axis  
**for y-axis**  
"Y-AXIS," & $$.payload.Y-AXIS & $moment().tz("Asia/Tokyo").format(",DD/MM/YYYY,h:mm:ss a")  
**for z-axis**  
"Z-AXIS," & $$.payload.Z-AXIS & $moment().tz("Asia/Tokyo").format(",DD/MM/YYYY,h:mm:ss a")

the result,(probably due to function split,,as im changing to JSON string will fix it and repost)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f57b96303ec1af803751d0cb787afcf13d465f22.png)

---

<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:** [27 July 2021 17:53 UTC](https://discourse.nodered.org/t/help-how-to-add-timestamp-into-csv-file/48973/6 "2021-07-27T17:53:54Z")

</div>

You have changed the payload coming in from the mqtt node.  
you no longer need the function node. I did mention this in the other thread.

---

<div class="post-metadata">

**Author:** ![puteramelaka](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/puteramelaka/32/45520_2.png) [@puteramelaka](https://discourse.nodered.org/u/puteramelaka)\
**Post date:** [27 July 2021 17:55 UTC](https://discourse.nodered.org/t/help-how-to-add-timestamp-into-csv-file/48973/7 "2021-07-27T17:55:09Z")

</div>

yes, i did remove the function node but error occoured, i did send picture of the result to the other thread

---

<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:** [27 July 2021 17:56 UTC](https://discourse.nodered.org/t/help-how-to-add-timestamp-into-csv-file/48973/8 "2021-07-27T17:56:10Z")

</div>

Pictures are no good we need to see the expression you edited, we can not mind read the info.

---

<div class="post-metadata">

**Author:** ![puteramelaka](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/puteramelaka/32/45520_2.png) [@puteramelaka](https://discourse.nodered.org/u/puteramelaka)\
**Post date:** [27 July 2021 17:57 UTC](https://discourse.nodered.org/t/help-how-to-add-timestamp-into-csv-file/48973/9 "2021-07-27T17:57:27Z")

</div>

ok noted, i will share the info

---

<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:** [27 July 2021 17:59 UTC](https://discourse.nodered.org/t/help-how-to-add-timestamp-into-csv-file/48973/10 "2021-07-27T17:59:22Z")

</div>

@dceejay @Colin can you merge the threads as they are about the same thing.

> [@Help| how to split string from mqtt](https://discourse.nodered.org/t/help-how-to-split-string-from-mqtt/48931):
>
> i have send reading of accelerometer from MQTT to node-red in three axis (x -axis,y-axis and z-axis). however the message recieved is in the form of string. i have been watching youtube and reading google etc.i found that by using split node we are able to split the data from line that conisist xyz into a own line x , y and z .after split the data i want to save as csv and build graph from the reading.Since i am very new its quite confusing and im quite lost.i will show image detail below to ma…

---

<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:** [25 September 2021 18:00 UTC](https://discourse.nodered.org/t/help-how-to-add-timestamp-into-csv-file/48973/11 "2021-09-25T18:00:20Z")

</div>

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