# Converting MODBUS data to date-time with Array

**URL:** <https://discourse.nodered.org/t/converting-modbus-data-to-date-time-with-array/76060>\
**Category:** General\
**Created:** [3 March 2023 14:31 UTC](https://discourse.nodered.org/t/converting-modbus-data-to-date-time-with-array/76060 "2023-03-03T14:31:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sefaguntepe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sefaguntepe/32/94497_2.png) [@sefaguntepe](https://discourse.nodered.org/u/sefaguntepe)\
**Post date:** [3 March 2023 14:31 UTC](https://discourse.nodered.org/t/converting-modbus-data-to-date-time-with-array/76060/1 "2023-03-03T14:31:30Z")

</div>

Hello, how can I convert the quad data from MODBUS to date-time?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/89b9f35944e5f4654c89ad70360e560dee739c0b.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7d5d544e038a34d3df24d7354e7352ebf84c2d28.png)

```auto
0: 23
1: 514
2: 2310
3: 59000

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 March 2023 14:43 UTC](https://discourse.nodered.org/t/converting-modbus-data-to-date-time-with-array/76060/2 "2023-03-03T14:43:50Z")

</div>

there are many ways that data could be encoded.

Can you tell us what where this data comes from?  
Does the data source have a page in a manual that describes how it is formatted?

Worst case, can you tell us what time you expect those values to become?

---

<div class="post-metadata">

**Author:** ![sefaguntepe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sefaguntepe/32/94497_2.png) [@sefaguntepe](https://discourse.nodered.org/u/sefaguntepe)\
**Post date:** [3 March 2023 15:19 UTC](https://discourse.nodered.org/t/converting-modbus-data-to-date-time-with-array/76060/3 "2023-03-03T15:19:23Z")

</div>

SE's electricity meter. Detail I found in the related document.

```auto
DATETIME	DateTime	1/1/2000 – 12/31/2127	0xFFFFFFFFFFFFFFFF	"DateTime coding format using 4 words as per IEC 870-5-4

Word 1
   b0-b6: Year (0 - 127)
   b7-b15: Reserved
Word 2
   b0-b4: Day (1-31)
   b5-b7: Weekday (1-7, 0 if not used)
   b8-b11: Month (1-12)
   b12-b15: Reserved
Word 3
   b0-b5: Minutes (0-59)
   b6: Reserved
   b7: Time synchronization quality, 1 = non valid or non synchronization
   b8-b12: Hour (0-23)
   b13-b14: Reserved
   b15: 0 = Standard time, 1 = Daylight Savings Time
Word 4
   b0-b15: Millisecond (0 - 59999)
"

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 March 2023 15:48 UTC](https://discourse.nodered.org/t/converting-modbus-data-to-date-time-with-array/76060/4 "2023-03-03T15:48:14Z")

</div>

ok, well based on that info, I get this...

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af13538cd15d8be7bd54f74c271b20b565400bdc.png)

Demo Flow (use `CTRL+I` to import)

```auto
[{"id":"29323ef4aa510c2a","type":"buffer-parser","z":"83556a18e3c2c577","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint16be","name":"year","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"0x007F"},{"type":"uint16be","name":"day","offset":2,"length":1,"offsetbit":0,"scale":"1","mask":"0x000F"},{"type":"uint16be","name":"weekday","offset":2,"length":1,"offsetbit":0,"scale":">> 4","mask":"0x00F0"},{"type":"uint16be","name":"month","offset":2,"length":1,"offsetbit":0,"scale":">> 8","mask":"0x0F00"},{"type":"uint16be","name":"minutes","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":"0x001F"},{"type":"bool","name":"synchronization ","offset":4,"length":1,"offsetbit":7,"scale":"1","mask":""},{"type":"uint16be","name":"hour","offset":4,"length":1,"offsetbit":8,"scale":">> 8","mask":"0x1F00"},{"type":"uint16be","name":"millisecond","offset":6,"length":1,"offsetbit":8,"scale":">> 8","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":280,"y":940,"wires":[["d8b0fecef27998f5"]]},{"id":"e1f83894c0a794d9","type":"inject","z":"83556a18e3c2c577","name":"[23,514, 2310, 59000]","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[23,514, 2310, 59000]","payloadType":"json","x":300,"y":860,"wires":[["29323ef4aa510c2a"]]},{"id":"d8b0fecef27998f5","type":"debug","z":"83556a18e3c2c577","name":"debug 158","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":440,"y":940,"wires":[]}]

```

It may not be 100% correct (I might have the wrong bits or masks set) but it should give you the right direction.

PS, if you want the final result to be an actual JS Date object (or a Epoch timestamp) then you will need to use a function node and the `Date` object to built it from the components in the buffer-parser result.

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [3 March 2023 16:07 UTC](https://discourse.nodered.org/t/converting-modbus-data-to-date-time-with-array/76060/5 "2023-03-03T16:07:18Z")

</div>

> [@sefaguntepe](#):
>
> SE's electricity meter

As a matter of interest, is that from a so called 'smart meter'? If so, how are you collecting the data?

---

<div class="post-metadata">

**Author:** ![mudwalker](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mudwalker](https://discourse.nodered.org/u/mudwalker)\
**Post date:** [3 March 2023 16:11 UTC](https://discourse.nodered.org/t/converting-modbus-data-to-date-time-with-array/76060/6 "2023-03-03T16:11:52Z")

</div>

Also SE stands for?

---

<div class="post-metadata">

**Author:** ![sefaguntepe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sefaguntepe/32/94497_2.png) [@sefaguntepe](https://discourse.nodered.org/u/sefaguntepe)\
**Post date:** [3 March 2023 17:09 UTC](https://discourse.nodered.org/t/converting-modbus-data-to-date-time-with-array/76060/7 "2023-03-03T17:09:43Z")

</div>

Can you teach me how you did it?

---

<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 March 2023 17:10 UTC](https://discourse.nodered.org/t/converting-modbus-data-to-date-time-with-array/76060/8 "2023-03-17T17:10:05Z")

</div>

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