# Store only the last 24 hours' Data

**URL:** <https://discourse.nodered.org/t/store-only-the-last-24-hours-data/65252>\
**Category:** General\
**Created:** [18 July 2022 09:39 UTC](https://discourse.nodered.org/t/store-only-the-last-24-hours-data/65252 "2022-07-18T09:39:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyntia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cyntia/32/64546_2.png) [@cyntia](https://discourse.nodered.org/u/cyntia)\
**Post date:** [18 July 2022 09:39 UTC](https://discourse.nodered.org/t/store-only-the-last-24-hours-data/65252/1 "2022-07-18T09:39:01Z")

</div>

Hello.  
I'm receiving Data each second from a Database and with the help of the Write and read node and I store my data each minutes. I can delete the stored Data by configuiring another write note as delete instead of overwrite or append but that delete the complete file.

My question is that: is there a way to delete only data older than 24 hours rather than the complete file?

Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [18 July 2022 09:43 UTC](https://discourse.nodered.org/t/store-only-the-last-24-hours-data/65252/2 "2022-07-18T09:43:51Z")

</div>

Hi,  
Depends on the database you are using.  
With a influx database you can make a continues query that will do the job for you. Other databases you can make your own query do delete data older then 24H.

---

<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:** [18 July 2022 09:46 UTC](https://discourse.nodered.org/t/store-only-the-last-24-hours-data/65252/3 "2022-07-18T09:46:45Z")

</div>

You don't mention how you store your data to file, i.e. what format. If there is a timestamp you could load the file, delete lines with timestamp older than 24 hr attach new lines and save. Or if no timestamp you could load file, delete all line except last 1440(1 day in mins), attach new line and save.

---

<div class="post-metadata">

**Author:** ![cyntia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cyntia/32/64546_2.png) [@cyntia](https://discourse.nodered.org/u/cyntia)\
**Post date:** [18 July 2022 09:47 UTC](https://discourse.nodered.org/t/store-only-the-last-24-hours-data/65252/4 "2022-07-18T09:47:12Z")

</div>

Thanks @E1cid  
I expressed myself wrongly. I mean storing it in node red(file).

---

<div class="post-metadata">

**Author:** ![cyntia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cyntia/32/64546_2.png) [@cyntia](https://discourse.nodered.org/u/cyntia)\
**Post date:** [18 July 2022 09:50 UTC](https://discourse.nodered.org/t/store-only-the-last-24-hours-data/65252/5 "2022-07-18T09:50:04Z")

</div>

I store it in a .txt file. and I have and yes I have added an inject node with timestamps.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 July 2022 10:02 UTC](https://discourse.nodered.org/t/store-only-the-last-24-hours-data/65252/6 "2022-07-18T10:02:32Z")

</div>

If you want to be able to do things like delete data before a certain time then you would be better to use a database. Then it is trivial.

---

<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:** [1 August 2022 10:03 UTC](https://discourse.nodered.org/t/store-only-the-last-24-hours-data/65252/7 "2022-08-01T10:03:24Z")

</div>

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