-1

I wanted to know as how to get the start date and end date by passing the month name to a function like:

var myMonth="September 2015"

?

I tried this link Get first and last date but the input is different from the one that is in the link

Community
  • 1
  • 1
forgottofly
  • 2,729
  • 11
  • 51
  • 93
  • There is no such a function available built-in. Good news though: you can implement one yourself. – zerkms Sep 28 '15 at 05:01
  • 2
    1. The question is unclear, you should show the input and expected output. 2. You should show your efforts to solve the problem – Tushar Sep 28 '15 at 05:04

1 Answers1

0

By your question I think you want to get the particular months first date and last date. I can suggest the following:

For first date:

var myMonth="September 2015" 
myMonth = "1 "+myMonth;
var d = new Date(myMonth);
d.getDate(); // will give the start date of the month

For last date:

var myMonth="September 2015" 
myMonth = "1 "+myMonth;
var checkDate = new Date(myMonth);
var d = new Date(checkDate.getFullYear(), checkDate.getMonth() + 1, 0);
d.getDate(); // this will return the last date of the month

Here is the fiddle: http://jsfiddle.net/swaprks/5z2s2myt/

Swaprks
  • 1,553
  • 11
  • 16
  • `new Date("September 2015")` returns `Invalid Date` – caasjj Sep 28 '15 at 05:37
  • Can I get the date in this formar :StartDate:01-09-2015 and EndDate: 30-09-2015? – forgottofly Dec 04 '15 at 06:22
  • You can get the date object and from that you can make the date as : dateObj.getDate() +"-"+ (dateObj.getMonth()+1) +"-"+ dateObj.getFullYear(). Plus one for month because it starts from 0. – Swaprks Dec 05 '15 at 08:05