0

In my jQuery code I am calling a controller action and I'm trying to pass in dates from the fullcalendar plugin:

url: ('Home/List/?dateValueStart=' +  new Date($('#calendar').fullCalendar('getView').start))
+ '&dateValueEnd=' + new Date($('#calendar').fullCalendar('getView').end),

In my controller I have my method setup like this:

public ActionResult List(String dateValueStart, String dateValueEnd)

When I debug dateValueStart I see this:

Tue Oct 1 00:00:00 MDT 2013

DateTime dateVal = Convert.ToDateTime(dateValueStart);

But when I try to convert this to a date it tells me it is invalid.

String was not recognized as a valid DateTime.

How can I get a date close to 10/1/2013?

webdad3
  • 8,893
  • 30
  • 121
  • 223

1 Answers1

0

Javascript date support isn't the greatest. There are shorter ways to do the following but they don't work in all browsers:

var formatDate = function(d){
    var curr_date = d.getDate();
    var curr_month = d.getMonth() + 1; //Months are zero based
    var curr_year = d.getFullYear();
    return curr_month + "/" + curr_date + "/" + curr_year;
}

var startDate = new Date($('#calendar').fullCalendar('getView').start);
var endDate = new Date($('#calendar').fullCalendar('getView').end);

var url = 'Home/List/?dateValueStart=' + formatDate(startDate) + '&dateValueEnd=' +
formatDate(endDate)

Also, check out this

Community
  • 1
  • 1
John Wu
  • 50,556
  • 8
  • 44
  • 80