# How to insert a Timestamp in a CSV for each parsed tweet

**URL:** <https://discourse.nodered.org/t/how-to-insert-a-timestamp-in-a-csv-for-each-parsed-tweet/5733>\
**Category:** General\
**Created:** [12 December 2018 22:24 UTC](https://discourse.nodered.org/t/how-to-insert-a-timestamp-in-a-csv-for-each-parsed-tweet/5733 "2018-12-12T22:24:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kypez](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kypez/32/4464_2.png) [@Kypez](https://discourse.nodered.org/u/Kypez)\
**Post date:** [12 December 2018 22:24 UTC](https://discourse.nodered.org/t/how-to-insert-a-timestamp-in-a-csv-for-each-parsed-tweet/5733/1 "2018-12-12T22:24:46Z")

</div>

Dear community,

i am new to Node Red and hope that my question is not too obvious. However, i did not find any thread, related to my current challange.

So what i am currently doing is a twitter parser to CSV. Parsing from twitter to a csv file works like a charm, but the tweets are parsed without timestamps. Could you kindly help me to insert an additional timestamp in an extra column in the created csv file?

Attached you can see the current build of my flow:

 ![Twitter-CSV](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/240363c94eaa64b5a8ef93cfe738eeb1c008f3d7.png)

Thank you a lot in advance for any help.

Kind Regards

D. Petrik

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [12 December 2018 22:50 UTC](https://discourse.nodered.org/t/how-to-insert-a-timestamp-in-a-csv-for-each-parsed-tweet/5733/2 "2018-12-12T22:50:23Z")

</div>

You posted this in core development which if you read the description is for developers helping to write to core part of Node-RED. I’ve therefore moved it to the more appropriate #general

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [12 December 2018 22:53 UTC](https://discourse.nodered.org/t/how-to-insert-a-timestamp-in-a-csv-for-each-parsed-tweet/5733/3 "2018-12-12T22:53:03Z")

</div>

You should be able to get the current time stamp using the contrib-moment node, or by using javascript in a function node that you can then add to the message object for passing to a csv file. Have a go and if you get stuck come back and show us where you’ve got to

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [12 December 2018 23:09 UTC](https://discourse.nodered.org/t/how-to-insert-a-timestamp-in-a-csv-for-each-parsed-tweet/5733/4 "2018-12-12T23:09:46Z")

</div>

Here is a function node that will show you how to build up the string required to be put into the file

```auto
var topic = msg.topic;
if (msg.payload === "1") {
    var p = "On";
    } 
else if (msg.payload === "0") { 
    var p = "Off";
    }
else var p = "Unknown";

var d = flow.get("MyDateTime") || "0";
//var myCount = flow.get("count", storeName);

//create message to write to the log file
var payload1 = (d + " Tank Pump is " + p + " Topic is: " + msg.topic);
//Store message so it can be output on output 1
var msg1 = { payload:payload1 };

//Create 2nd message for screen writing on scrolling table
var payload2 = (d + " Tank Pump is " + p);
//Store message so it can be output on output 2
var msg2 = { payload:payload2 };

if (p == "On") {
var msg3 = { payload:'<i class="fa fa-refresh fa-spin fa-3x fa-fw"></i>' };
}

if (p == "Off") {
var msg3 = { payload:'<i class="fa fa-stop-circle-o fa-3x fa-fw"></i>' };
}

//End Function and return two messages on two outputs
return [msg1, msg2, msg3,];

```

I use the Contrib moment function to build a Global variable that is stored in another function and then referenced in here

Craig

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [13 December 2018 06:55 UTC](https://discourse.nodered.org/t/how-to-insert-a-timestamp-in-a-csv-for-each-parsed-tweet/5733/5 "2018-12-13T06:55:55Z")

</div>

> [@Kypez](#):
>
> Could you kindly help me to insert an additional timestamp in an extra column in the created csv file?

I use node-red-contrib-simpletime to add date/time info to msgs

> **[node-red-contrib-simpletime](https://flows.nodered.org/node/node-red-contrib-simpletime)**
>
> A lightweight node-red node to provide and format date and time.

---

<div class="post-metadata">

**Author:** ![Kypez](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kypez/32/4464_2.png) [@Kypez](https://discourse.nodered.org/u/Kypez)\
**Post date:** [13 December 2018 07:22 UTC](https://discourse.nodered.org/t/how-to-insert-a-timestamp-in-a-csv-for-each-parsed-tweet/5733/6 "2018-12-13T07:22:07Z")

</div>

Thank you guys for the suggestions and for the moving the thread to the general section. My bad.

I see - there is no predefined node for this - only the possibility to write a function. I will try out the node and the fuction code and report 🙂

Kind Regards

---

<div class="post-metadata">

**Author:** ![Kypez](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kypez/32/4464_2.png) [@Kypez](https://discourse.nodered.org/u/Kypez)\
**Post date:** [22 December 2018 23:19 UTC](https://discourse.nodered.org/t/how-to-insert-a-timestamp-in-a-csv-for-each-parsed-tweet/5733/7 "2018-12-22T23:19:15Z")

</div>

Thanks guys.

I have figured it out and inserted the following code between the twitter input node and the tweets node:

var tweets = msg.payload;  
var TweetPayload = {};  
TweetPayload.date = new Date().toString();  
TweetPayload.tweet = tweets;  
msg.payload = TweetPayload;  
return msg;

I failed somehow to use the node-red-contrib-simpletime :-X I assume that it also requires additional code to get it work.

Kind Regards
