I assumed that if the current month is February, then your conclusion should be 1,31 , because the first day of January and the last day are 1 and 31. So, if that is so, then
var toDay = new Date(); var myDate = new Date(2016,toDay.getMonth()-1); Fri Jan 01 2016 00:00:00 GMT+0530 (India Standard Time)
This will be assigned on the first day of the previous month.
In addition, for the second case
var myDate = new Date(2016, toDay.getMonth()); myDate = new Date(myDate -1); Sat Jan 31 2015 23:59:59 GMT+0530 (India Standard Time)
You can simply use myDate to find whatever you want.
source share