Writing to .txt file using Node-RED. Want to write to a new file name depending on timestamp, etc

I am using a GRV-EPIC-PR2 with serial module GRV-CSERI-4. I have an RS-232 stream connecting a serial device to the serial module and have a connection configured in Node-RED so that every time the serial device is cycled (it is an ultrasonic welder), a text string is written to a new line on a .txt file using the Write File node in Node-RED.

Is there a way to use Node-RED to conditionally write to a new .txt file depending on a different input, or depending on a part of the text string?

Specifically, I would want to start writing to a new text file on each new working day.

Example:
Text string comes through with timestamp indicating that the date is 01-03-2024. I want that string written to a .txt file. If a second string comes through with the same date (01-03-2024), I want that string written to the next line on that same .txt file.

A third string comes through with timestamp date 01-05-2024. Since the date has changed, I want that string written to a new .txt file (and any string that is received with the same timestamp date should be written to the same .txt file). And so on, and so forth.


Welcome to the Opto Forums Matt.

Yes, its a common request.
You can see some solutions here:

And here:

The moment node in conjunction with a RBE/Filter (Report by exception) node will probably do what you are looking for.
The RBE will only output once the date rolls over at midnight, till then, the data will go into the current file.