Get First Day and Last Day of Month

Hello,

i am triyng to get first and last day of a month

I have seen this example but not working for me…

image

What i am doing.

image

It gives me this.

image

What i am missing?

Thanks in Advance!

does it work like this?

this.date_inicial = new Date();
this.date_inicial.setDate(1);

Otherwise you could consider using momentjs

http://momentjs.com

And there, didn’t tried but, you could find an example about how to find first and last day of the month:

Your code doesn´t work.

Using Moment JS i get the same start date??

image

image

Thanks in Advance!

That code works like a charm sorry:

let date_inicial:Date = new Date();
date_inicial.setDate(1);

console.log('---> ' + date_inicial);
console.log('---> ' + date_inicial.toDateString());
console.log('---> ' + date_inicial.toISOString());

Give back

---> Sat Oct 01 2016 13:31:00 GMT+0200 (CEST)
---> Sat Oct 01 2016
---> 2016-10-01T11:33:31.000Z

Thanks! It works!

Do you have the code for last day of month?

I think that because leap year i am getting 30/09 for first day of October…

Didn’t tried but maybe

 let next_month:Date = new Date();
 next_month.setMonth(next_month.getMonth() + 1);
 let data_final:Date = new Date(next_month - 1);

…but as I said didn’t tried