# How to split up a message

**URL:** https://discourse.nodered.org/t/how-to-split-up-a-message/36148
**Category:** General
**Created:** [18 November 2020 15:37 UTC](https://discourse.nodered.org/t/how-to-split-up-a-message/36148 "2020-11-18T15:37:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Kouwe-sudo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kouwe-sudo/32/32202_2.png) [@Kouwe-sudo](https://discourse.nodered.org/u/Kouwe-sudo)
#### Post date: [18 November 2020 15:37 UTC](https://discourse.nodered.org/t/how-to-split-up-a-message/36148/1 "2020-11-18T15:37:55Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)
#### Post date: [18 November 2020 15:58 UTC](https://discourse.nodered.org/t/how-to-split-up-a-message/36148/2 "2020-11-18T15:58:45Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Kouwe-sudo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kouwe-sudo/32/32202_2.png) [@Kouwe-sudo](https://discourse.nodered.org/u/Kouwe-sudo)
#### Post date: [18 November 2020 16:13 UTC](https://discourse.nodered.org/t/how-to-split-up-a-message/36148/3 "2020-11-18T16:13:15Z")

</div>

Yes, it does.

---

<div class="post-metadata">

### Author: ![softy2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/softy2k/32/23707_2.png) [@softy2k](https://discourse.nodered.org/u/softy2k)
#### Post date: [18 November 2020 16:15 UTC](https://discourse.nodered.org/t/how-to-split-up-a-message/36148/4 "2020-11-18T16:15:20Z")

</div>

Try this :

```auto
[{"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":[]}]

```

---

<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 November 2020 16:15 UTC](https://discourse.nodered.org/t/how-to-split-up-a-message/36148/5 "2020-11-18T16:15:42Z")

</div>

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

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

### Author: ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)
#### Post date: [18 November 2020 16:18 UTC](https://discourse.nodered.org/t/how-to-split-up-a-message/36148/6 "2020-11-18T16:18:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Kouwe-sudo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kouwe-sudo/32/32202_2.png) [@Kouwe-sudo](https://discourse.nodered.org/u/Kouwe-sudo)
#### Post date: [18 November 2020 16:28 UTC](https://discourse.nodered.org/t/how-to-split-up-a-message/36148/7 "2020-11-18T16:28:02Z")

</div>

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.

---

<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: [17 January 2021 16:28 UTC](https://discourse.nodered.org/t/how-to-split-up-a-message/36148/8 "2021-01-17T16:28:10Z")

</div>

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