# \[node-red-contrib-simpletime\]mydate

**URL:** <https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900>\
**Category:** General\
**Created:** [6 September 2018 07:32 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900 "2018-09-06T07:32:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 September 2018 07:32 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/1 "2018-09-06T07:32:37Z")

</div>

@Paul-Reed (I'm assuming this is yours but maybe there are two paul-reeds :)) )

I LOVE this node and use it a lot as a method of inline debugging timestamping 🙂

But I also use it to add **mydate** to tweets and I wondering if it could be tweaked slightly?

It currently looks like

Thu Sep 06 2018

and I was thinking that it might look better as

Thu 6 Sep 2018

Its no big deal at all but what do you think?

Simon

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [6 September 2018 07:37 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/2 "2018-09-06T07:37:34Z")

</div>

I thought you were out of suggestions for September ? 🙂

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 September 2018 07:40 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/3 "2018-09-06T07:40:08Z")

</div>

Only for core 🙂

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [6 September 2018 07:41 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/4 "2018-09-06T07:41:10Z")

</div>

carry on !

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 September 2018 09:16 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/5 "2018-09-06T09:16:51Z")

</div>

Looks like he has the date in the format used in the US. Why not add a RFE or PR to the node asking for an option to specify the format? Of course then it will be the 'alittlelessthansimpletime' node 😜

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 September 2018 10:12 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/6 "2018-09-06T10:12:34Z")

</div>

> [@zenofmud](#):
>
> Looks like he has the date in the format used in the US.

aah - fair enough then 🙂

> [@zenofmud](#):
>
> Why not add a RFE or PR to the node asking for an option to specify the format?

I wouldn't want to do that as I too, don't want it to be "alittlelessthansimple' node 🙂

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [6 September 2018 21:22 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/7 "2018-09-06T21:22:57Z")

</div>

I would have preferred to see the date formatted Thu 6 Sep 2018, but as the node obtains the date by using;

```auto
var d = new Date();
msg.mydate = d.toDateString();

```

..which returns Thu Sep 06 2018 as it's the default format returned by javascript.

But it can be done, try importing the attached flow, and let me know what you think.

Paul

```auto
[
    {
        "id": "8118cf57.cbf43",
        "type": "function",
        "z": "f82b93ba.98aad",
        "name": "simpletime",
        "func": "const monthNames = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"June\", \"July\", \"Aug\", \"Sept\", \"Oct\", \"Nov\", \"Dec\"];\nconst dayNames =[\"Sun\", \"Mon\", \"Tues\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"];\nvar d = new Date();\n dt = d.toDateString();\n e = d.getTime();\n h = (d.getHours());\n m = (d.getMinutes());\n mn = (monthNames[d.getMonth()]);\n dy = (dayNames[d.getDay()]);\n dt = d.getDate();\n yr = d.getFullYear();\n \n if (m < 10) {\n var min = '0' + m;\n }\n else (min = m);\n s = (d.getSeconds());\n if (s < 10) {\n var sec = '0' + s;\n }\n else (sec = s);\n var tm = (h+\":\"+min);\n var tms = (h+\":\"+min+\":\"+sec);\n var ms = (min+\":\"+sec);\n var sd = (dy+\", \"+dt+\" \"+mn+\" \"+yr);\n \n msg.myrawdate = d;\n msg.myepoch = e;\n msg.mysecond = s;\n msg.myminute = m;\n msg.myminutes = ms;\n msg.myhour = h;\n msg.mytime = tm;\n msg.mytimes = tms;\n msg.mydate = sd;\n\n node.send(msg);\n ",
        "outputs": 1,
        "noerr": 0,
        "x": 440,
        "y": 390,
        "wires": [
            [
                "4540b623.bebb58"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 September 2018 21:35 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/8 "2018-09-06T21:35:00Z")

</div>

> [@Paul-Reed](#):
>
> But it can be done, try importing the attached flow, and let me know what you think.

Your flow is fine

I made one in Blockly to do very similar while I was waiting around this afternoon 🙂

So, are you up for rolling that into your contrib-node itself? (More than willing to do the coding changes and issue a pull-request on your GitHub repository if your busy with other stuff)

Simon

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [6 September 2018 21:45 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/9 "2018-09-06T21:45:46Z")

</div>

> [@cymplecy](#):
>
> ...while I was waiting around this afternoon

Sorry if I kept you waiting Simon!  
Aahh, the benefits of being semi-retired 🕶🕶🕶

Paul

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [6 September 2018 21:53 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/10 "2018-09-06T21:53:10Z")

</div>

I can do the update, but let's see if there is other feedback which we may need to consider before doing so.

Paul

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 September 2018 21:58 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/11 "2018-09-06T21:58:21Z")

</div>

> [@Paul-Reed](#):
>
> but let's see if there is other feedback which we may need to consider before doing so

Patience is my middle name 🙂

---

<div class="post-metadata">

**Author:** ![nodecentral](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodecentral/32/10432_2.png) [@nodecentral](https://discourse.nodered.org/u/nodecentral)\
**Post date:** [6 September 2018 22:21 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/12 "2018-09-06T22:21:04Z")

</div>

Hi, Please could someone share any flow examples they have that use simpletime, I tried it a short while ago - to I think convert an epoch/unix time into something human readable - but I could not get it to work. ☹

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 September 2018 22:21 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/13 "2018-09-06T22:21:38Z")

</div>

I think that this is an issue where it depends on where in the world and how you normally expect the date to look. I'm in the US and would want it in Month, Day Year because that is the convention I am use to. Others will want it Day, Month year.

So unless you give people the option to choose the format they want, any change will pelase some and sadden others who may request the opposite in a PR in the future.

My two cents

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [6 September 2018 22:33 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/14 "2018-09-06T22:33:02Z")

</div>

It seems that using d.toLocaleDateString() instead of d.toDateString() ought to help, but I'm stuck in a place where it makes no difference, and I've had no luck experimenting with `locales` and `options` arguments inside a `function` node. In any case, I think the simple solution is to get the format that is customary where you live and use something alittlelessthansimple if you want different.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 September 2018 22:36 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/15 "2018-09-06T22:36:22Z")

</div>

> [@nodecentral](#):
>
> Please could someone share any flow examples they have that use simpletime,

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/08567f275b5fb46ef207df1783e2f37f771b540a.png)

```
[{"id":"c4d7e0f.675742","type":"inject","z":"c84eeaca.be45c8","name":"","topic":"","payload":"red","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":360,"wires":[["d957d526.acd958"]]},{"id":"f6ebc6c6.aa2c08","type":"debug","z":"c84eeaca.be45c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":850,"y":360,"wires":[]},{"id":"d957d526.acd958","type":"simpletime","z":"c84eeaca.be45c8","name":"","x":350,"y":360,"wires":[["12b6c2ca.78732d"]]},{"id":"12b6c2ca.78732d","type":"change","z":"c84eeaca.be45c8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"\"Colour is \" & payload & \" and the date is \" & mydate","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":360,"wires":[["f6ebc6c6.aa2c08"]]}]

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [6 September 2018 22:42 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/16 "2018-09-06T22:42:19Z")

</div>

Unfortunately not ... The node.js binary is not built by default with all the locale awareness needed for toLocaleString to do the right thing.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [6 September 2018 22:45 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/17 "2018-09-06T22:45:19Z")

</div>

Thanks, Nick. I can rest now. Not a big fan of `locales` anyway but a heavy user of the `moment` node.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [6 September 2018 22:48 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/18 "2018-09-06T22:48:37Z")

</div>

> [@knolleary](#):
>
> The node.js binary is not built by default with all the locale awareness needed for toLocaleString to do the right thing.

Ah yes, been there, been burned by that... but the `node-red-contrib-moment` node _is_ .  
Simon, you can get the date format you want by specifying the format `ddd D MMM YYYY`

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/64d422f0d4170aca224c4436cc1481244b3f6302.png)

Here is an example flow:

```auto
[{"id":"3ad33994.9a7d56","type":"inject","z":"58c8eb7a.5496c4","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":860,"y":2920,"wires":[["f7be760e.adf2e8"]]},{"id":"f7be760e.adf2e8","type":"moment","z":"58c8eb7a.5496c4","name":"","topic":"","input":"","inputType":"msg","inTz":"America/New_York","adjAmount":0,"adjType":"days","adjDir":"add","format":"ddd D MMM YYYY","locale":"en_US","output":"","outputType":"msg","outTz":"America/New_York","x":980,"y":2960,"wires":[["b295243a.29e318"]]},{"id":"b295243a.29e318","type":"debug","z":"58c8eb7a.5496c4","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","x":1100,"y":3000,"wires":[]}]

```

_(sorry, I know it doesn't actually answer the question about how to use simpletime...)_

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 September 2018 22:54 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/19 "2018-09-06T22:54:34Z")

</div>

> [@shrickus](#):
>
> Simon, you can get the date format you want by specifying the format `ddd D MMM YYYY`

Thanks 🙂

> [@shrickus](#):
>
> (sorry, I know it doesn't actually answer the question about how to use simpletime...)

No forum question ever survives the OP 🙂

But good to know there is the nuclear option if required  
I just wanted the day of the month before the name of month and drop the leading zero ........... 🙂

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [6 September 2018 23:05 UTC](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900/20 "2018-09-06T23:05:15Z")

</div>

In all fairness the current

**www mmm dd yyyy**

format is a good computer choice as its easily parsed using sub-strings to produce anything anyone wants

**www, [d]d mmm[m] yyyy**

isn't quite so easy (could still be parsed by using split by space though)

[Next page](https://discourse.nodered.org/t/node-red-contrib-simpletime-mydate/2900.md?page=2)
