0

I'm trying to get the last day of a given month and year. The user has the option to insert the month and year in the following format mm.yyyy (e.g. 08.2020).

I'm trying to get the first day and the last day of the given month:

let dtFrom = '01.' + $('#month_from').val(); // adds 01. to the month.year to get the first 

let dateFrom = new Date(dtFrom);
let LastDay = new Date(dateFrom.getFullYear(), dateFrom.getMonth() + 1, 0);
let lastDayFormat = ((LastDay.getDate() > 9) ? LastDay.getDate() : (LastDay.getDate()));

console.log('lastDayFormat: ' + LastDayFormat);

when testing, it works using chrome, but not firefox

enter image description here

lechnerio
  • 884
  • 1
  • 16
  • 44
  • Does this answer your question? [Calculate last day of month in JavaScript](https://stackoverflow.com/questions/222309/calculate-last-day-of-month-in-javascript) – Heretic Monkey Dec 03 '20 at 13:43
  • @HereticMonkey unfortunately not, the linked post was my first goto when trying to solve this issue. – lechnerio Dec 03 '20 at 13:44

1 Answers1

-1

Maybe you should try to get the correct date type for your localization. The main issue always is the hard to understand difference in date formats all over the world. eg. English and German....

schnurzli
  • 24
  • 2