i want to convert Datetime. I don’t know how to do this? It gives errors. nvarchar doesn’t convert to datetime.
startDate format : “11.03.2012”
My table :
STARTDATE datetime
ENDDATE datetime
public static int Insert(string startDate, string endDate)
{
Conn c = new Conn();
SqlParameter[] prms = new SqlParameter[]{
new SqlParameter("@STARTDATE", DateTime.ParseExact(startDate,"DD MM YYYY",null)),
new SqlParameter("@ENDDATE", DateTime.ParseExact(endDate,"DD MM YYYY",null)),
};
return Convert.ToInt32(c.getObjectSP("sp_Insert", prms));
}
With a date that is formatted like
"11.03.2012", you need to parse with the.in your format string.Also note that
DDandYYYYare not characters that are identified in the format string as parts of the datatime but are expected to be literals. See my example –ddfor 2 characters for days andyyyyfor 4 characters for year.