-5

I get his error at hnddate(hidden field value coming from date time picker):

String was not recognized as a valid DateTime.when converting a string to datetime parse the string to take the date before putting each variable

DateTime weekStartDate = GetFirstDayOfWeek(Convert.ToDateTime(hdndate.Value))
                                          .AddDays(0);
DateTime weekEndDate = weekStartDate.AddDays(14);

the query gets the startdate by comparing to a column in datatabse which is in 2014/04/28 and the datepicker (hnddate) has 28/04/2014 format.

user2525244
  • 91
  • 1
  • 2
  • 12

1 Answers1

1

Assuming hdndate.Value is actually a string and its value is "28/04/2014":

Replace this:

Convert.ToDateTime(hdndate.Value)

With this:

DateTime.ParseExact(hdndate.Value, "dd/MM/yyyy", CultureInfo.InvariantCulture);

DateTime.ParseExact allows you to specify the exact format of your input string, so that it can correctly generate a DateTime from it. In this case, your format is dd/MM/yyyy.

Grant Winney
  • 61,140
  • 9
  • 100
  • 152