-2

I am trying to get the last day of a month, it worked but it displays a very long description and I just need the day.

My code is this one:

var today = new Date();
var data = new Date(today.getFullYear(), today.getMonth()+1, 0);

and it returns

Sat Apr 30 2022 00:00:00 GMT-0400

But I just want to get the 30... only that

how can I do it? Thanks

Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
thecode
  • 11
  • 4
  • Does this answer your question? [Does Stack Overflow encourage developer laziness?](https://meta.stackexchange.com/questions/4448/does-stack-overflow-encourage-developer-laziness) – Yogi Apr 19 '22 at 20:30

2 Answers2

1

Use getDate() to get the day of the month.

var today = new Date();
var data = new Date(today.getFullYear(), today.getMonth()+1, 0).getDate(); // 30
Casper Kuethe
  • 1,070
  • 8
  • 13
0

getDate() returns the day of the month

var today = new Date();
var data = new Date(today.getFullYear(), today.getMonth()+1, 0);
var date = data.getDate();
Seano666
  • 2,238
  • 1
  • 15
  • 14