How to split up a message

I have a timestamp like this: '2020-11-18 16:31:27'
I would like to split it up in 4 different messages because I don't need the time but only the stamp (If you know what I mean).

I would like to have something like this:

year = 2020
month = 11
day = 18
rest = 16:31:27

so I can use the year, month and day in calculations. I searched the site (perhaps not good enough) but I couldn't find what I was looking for.
Is there someone out there who already figured this out and is willing to give me a clue?

Does the timestamp always have the same construct, year followed by dash followed by month etc?

Yes, it does.

Try this :

[{"id":"73e62ea7.bf04d","type":"inject","z":"9a0aafa6.af922","name":"Go","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":890,"y":1080,"wires":[["82a16da7.07cff"]]},{"id":"82a16da7.07cff","type":"function","z":"9a0aafa6.af922","name":"Split","func":"msg.payload = '2020-11-18 16:31:27';\n\nmsg.split = msg.payload.split(/[- ]/);\n\nmsg.year = msg.split[0];\nmsg.month = msg.split[1];\nmsg.day = msg.split[2];\nmsg.rest = msg.split[3];\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1050,"y":1080,"wires":[["cfe48367.a1aaa8"]]},{"id":"cfe48367.a1aaa8","type":"debug","z":"9a0aafa6.af922","name":"Split","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1210,"y":1080,"wires":[]}]

msg.payload = msg.payload.split(/\s|-/g);
In a function node

[{"id":"c815e9db.a393f8","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2020-11-18 16:31:27","payloadType":"str","x":470,"y":1760,"wires":[["dd06c3ac.4874a8"]]},{"id":"dd06c3ac.4874a8","type":"function","z":"8d22ae29.7df6d","name":"","func":"let payload= msg.payload.split(/\\s|-/g);\nmsg.payload={\"year\": payload[0],\n            \"month\":payload[1],\n            \"day\":payload[2],\n            \"time\":payload[3]}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":630,"y":1760,"wires":[["36b4efff.5e9fa"]]},{"id":"36b4efff.5e9fa","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":2000,"wires":[]}]

There you go several examples, however you don't say what kind of calculations you want to do. You may find it easier to convert your timestamp to epoch time then do your calculations then convert the answer back to human time.

Thank you for the help. This will do.
The calculations are pretty simple for the moment. I only want to know if the day is a new day, the month a new month and the year a new year.

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