# Writing updating of out time in csv file in node red

**URL:** <https://discourse.nodered.org/t/writing-updating-of-out-time-in-csv-file-in-node-red/86635>\
**Category:** General\
**Created:** [21 March 2024 12:15 UTC](https://discourse.nodered.org/t/writing-updating-of-out-time-in-csv-file-in-node-red/86635 "2024-03-21T12:15:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbadshahp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hbadshahp/32/87915_2.png) [@hbadshahp](https://discourse.nodered.org/u/hbadshahp)\
**Post date:** [21 March 2024 12:15 UTC](https://discourse.nodered.org/t/writing-updating-of-out-time-in-csv-file-in-node-red/86635/1 "2024-03-21T12:15:02Z")

</div>

Hii,

I am writing the sensor data with time stamp in csv file using Nodered. Now I want to store the in time and out time of sensor data in same row of csv because of memory management.

Example sensor1 in time punch at 21-03-2024 17:40 which I will store in csv file by linking sensor1 details. Now this sensor out time punch at 25-03-2024 11:40 which i want to update in above same row.

shall you suggest me some efficient way (Shall using iteration is the write way)

Thanks in advance

---

<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:** [21 March 2024 12:18 UTC](https://discourse.nodered.org/t/writing-updating-of-out-time-in-csv-file-in-node-red/86635/2 "2024-03-21T12:18:04Z")

</div>

The most efficient way would be to use a database. As rewriting to a line in a csv would use memory to read file, alter line and then save.

---

<div class="post-metadata">

**Author:** ![hbadshahp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hbadshahp/32/87915_2.png) [@hbadshahp](https://discourse.nodered.org/u/hbadshahp)\
**Post date:** [21 March 2024 12:23 UTC](https://discourse.nodered.org/t/writing-updating-of-out-time-in-csv-file-in-node-red/86635/3 "2024-03-21T12:23:58Z")

</div>

Thank you

But the limitation is to do work without database.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [21 March 2024 12:32 UTC](https://discourse.nodered.org/t/writing-updating-of-out-time-in-csv-file-in-node-red/86635/4 "2024-03-21T12:32:08Z")

</div>

> [@hbadshahp](#):
>
> the limitation is to do work without database.

Is this an educational exercise?

You could hold all the data as a (complicated) context variable using persistent storage, and provide an "Export as CSV" option.  
You could write your own code to manage a CSV file as if it was a database.  
Or you could use a database, already written and optimised for managing data.

The choice is up to you, or maybe whoever set your pointless limitation.

---

<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:** [21 March 2024 12:44 UTC](https://discourse.nodered.org/t/writing-updating-of-out-time-in-csv-file-in-node-red/86635/5 "2024-03-21T12:44:10Z")

</div>

Then maybe hold the line/object in separate file or context till the out time is added then write it to the csv.

---

<div class="post-metadata">

**Author:** ![AndrewBeasley](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@AndrewBeasley](https://discourse.nodered.org/u/AndrewBeasley)\
**Post date:** [21 March 2024 15:20 UTC](https://discourse.nodered.org/t/writing-updating-of-out-time-in-csv-file-in-node-red/86635/6 "2024-03-21T15:20:29Z")

</div>

No idea if you could do this in Node-Red but going way back in computing history (i.e. when I started) you had fixed length records in files and maintained your own index files (well posh folk using Cobol did not).

Each record was a fixed length so it was easy to work out the location of the record you wanted (record number \* record length - 1) and use this as an offset in the file...

I think (but never tried) Python still supports this with the open 'RB' options and the seek() function.

I would then use the sensor number as the record number, so for sensor 1 you have:

DD-MM-YYYY HH:MM = Record length 16 + 1 for Line Feed at the end

Record number = 1 for Sensor 1

Position in file = (1 \* 17) - 1 = Byte 16 is the start of the record

Note above assumes the first byte of the file is position zero and sensor numbers start at zero.

Technically this is not a CSV file as there are no commas in it - I would call this a plain text file for Linux (you would need to add a cr/lf at the end for Windows normally).

---

<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:** [19 June 2024 15:20 UTC](https://discourse.nodered.org/t/writing-updating-of-out-time-in-csv-file-in-node-red/86635/7 "2024-06-19T15:20:40Z")

</div>

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