# Last month day to write total energy month on DB

**URL:** <https://discourse.nodered.org/t/last-month-day-to-write-total-energy-month-on-db/13264>\
**Category:** General\
**Created:** [14 July 2019 13:46 UTC](https://discourse.nodered.org/t/last-month-day-to-write-total-energy-month-on-db/13264 "2019-07-14T13:46:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pautorras](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@pautorras](https://discourse.nodered.org/u/pautorras)\
**Post date:** [14 July 2019 13:46 UTC](https://discourse.nodered.org/t/last-month-day-to-write-total-energy-month-on-db/13264/1 "2019-07-14T13:46:57Z")

</div>

Hi,

I'm doing a node red program to report stats in dashboard on photovoltaic installation.  
I'm using a RPI and I'm working with SQLite DB.

Every last day of month, I want to write in a SQLite table the enery consumption of that month.

Actually, in a function with this code, I'm getting this result:

14/7/2019, 15:39:22[node: ab2700e4.732c7](http://192.168.1.141:1880/#)msg.payload : Date  
"Wed Jul 31 2019 00:00:00 GMT+0200 (GMT+02:00)"

Think it can work with a comparison on the actual date and time with this last day of month Date to write to DB.  
The only thing I would like to change in that result, is this, I wolud prefer this result:  
"Wed Jul 31 2019 23:59:59 GMT+0200 (GMT+02:00)"

This is the code I used in function:  
var today = new Date();  
var lastDayOfMonth = new Date(today.getFullYear(), today.getMonth()+1, 0);  
var outp={ payload: (lastDayOfMonth)};  
return [outp];

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [14 July 2019 13:56 UTC](https://discourse.nodered.org/t/last-month-day-to-write-total-energy-month-on-db/13264/2 "2019-07-14T13:56:15Z")

</div>

Have you tried specifying hours mins and seconds in your new Date line?  
eg

```auto
var lastDayOfMonth = new Date(today.getFullYear(), today.getMonth()+1, 0,23,59,59);

```

---

<div class="post-metadata">

**Author:** ![pautorras](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@pautorras](https://discourse.nodered.org/u/pautorras)\
**Post date:** [14 July 2019 15:26 UTC](https://discourse.nodered.org/t/last-month-day-to-write-total-energy-month-on-db/13264/3 "2019-07-14T15:26:19Z")

</div>

Yes, that's working perfect.  
Thanks @ukmoose
