The conversion of a varchar data type to a datetime data typ

Jul 20 2017 7:03 AM

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated
 
how to solve this problem.please anyone solve this problem.below this code:
 
 form aspx:
<div class="col-xs-12 col-sm-2 col-md-3 col-lg-3">

<label for="lblFromdate">
<span>From Date</span></label>
<dx:ASPxDateEdit ID="dtFrom" runat="server" ClientInstanceName="dtFrom" EditFormat="Custom" EnableTheming="false" DisplayFormatString="dd/MM/yyyy"
EditFormatString="dd/MM/yyyy" CssClass="form-control select">
<%-- <ClientSideEvents DateChanged="function(s,e){if(dtTo.GetText()!='')GrdLocBookRecord.PerformCallback();}" />--%>
</dx:ASPxDateEdit>
</div>
<div class="col-xs-12 col-sm-2 col-md-3 col-lg-3">
<label for="lblToDT">
<span>To Date</span></label>
<dx:ASPxDateEdit ID="dtTo" runat="server" ClientInstanceName="dtTo" EditFormat="Custom" EnableTheming="false" DisplayFormatString="dd/MM/yyyy"
EditFormatString="dd/MM/yyyy" CssClass="form-control select">
<%-- <ClientSideEvents DateChanged="function(s,e){if(dtFrom.GetText()!='')GrdLocBookRecord.PerformCallback();}" />--%>
</dx:ASPxDateEdit>
</div>
 
 
 
 
 
public static string SetDate(string date)
{
string setdate = null;
if (date != null && date != "")
{
DateTime dt = DateTime.ParseExact(date, "d/M/yyyy", CultureInfo.InvariantCulture);
// for both "1/1/2000" or "25/1/2000" formats
setdate = dt.ToString("dd/MM/yyyy");
//DateTime date1 = Convert.ToDateTime(date);
//var date2 = date1.Date;
//var D = date2.Day;
//var M = date2.Month;
//var y = date2.Year;
//string monthStr = M.ToString("00");
//setdate = D.ToString() + "/" + monthStr.ToString() + "/" + y.ToString();
}
//if (date != null && date != "")
// setdate = DateTime.Parse(date).ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
return setdate;
}
 
 
sanjida 


Answers (2)