# How to humanize date&time format in array of objects?

**URL:** <https://discourse.nodered.org/t/how-to-humanize-date-time-format-in-array-of-objects/57433>\
**Category:** General\
**Tags:** database\
**Created:** [28 January 2022 22:58 UTC](https://discourse.nodered.org/t/how-to-humanize-date-time-format-in-array-of-objects/57433 "2022-01-28T22:58:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![schejbity](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/schejbity/32/55579_2.png) [@schejbity](https://discourse.nodered.org/u/schejbity)\
**Post date:** [28 January 2022 22:58 UTC](https://discourse.nodered.org/t/how-to-humanize-date-time-format-in-array-of-objects/57433/1 "2022-01-28T22:58:36Z")

</div>

Hi all,

please could someone help me, how to humanize "created" property (for example: YYYY-MM-DD HH:mm) in whole array of objects on screenshot?  
It is output of MySQL node.

Many thanks.

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

---

<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:** [28 January 2022 23:07 UTC](https://discourse.nodered.org/t/how-to-humanize-date-time-format-in-array-of-objects/57433/2 "2022-01-28T23:07:28Z")

</div>

Try a function node with ..

```auto
msg.payload.forEach(e => {
  e.created = (new Date(e.created)).toString(); 
})
return msg;

```

I suspect this one is better suited to a change node & moment in JSONata

_(Untested, written on mobile)_

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [28 January 2022 23:20 UTC](https://discourse.nodered.org/t/how-to-humanize-date-time-format-in-array-of-objects/57433/3 "2022-01-28T23:20:43Z")

</div>

or do the Date convertion directly in mySql query using [`DATE_FORMAT(date` , _`format`_ )](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format)

For Example

`SELECT *, DATE_FORMAT(created, '%Y-%m-%d %H:%i:%s') as created FROM events ORDER BY id DESC LIMIT 50)`

---

<div class="post-metadata">

**Author:** ![schejbity](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/schejbity/32/55579_2.png) [@schejbity](https://discourse.nodered.org/u/schejbity)\
**Post date:** [29 January 2022 22:54 UTC](https://discourse.nodered.org/t/how-to-humanize-date-time-format-in-array-of-objects/57433/4 "2022-01-29T22:54:09Z")

</div>

Thank you, I like this solution.

---

<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:** [12 February 2022 22:54 UTC](https://discourse.nodered.org/t/how-to-humanize-date-time-format-in-array-of-objects/57433/5 "2022-02-12T22:54:20Z")

</div>

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