String was not recognized as a valid DateTime. Converting string to DateTime

You can only post once every 90 minutes. I'm trying to compare DateTime using If-statement. I'm having a problem converting my string to DateTime. The string value that I gotten from Gridview row is "24/01/2016". When I try converting, error will occur. "String was not recognized as a valid DateTime." But there is no problem converting when the value is "1/2/2016" Did I missed a step or the format was wrong?

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string startD = e.Row.Cells[3].Text; DateTime myDate = DateTime.Parse(startD); if (myDate < DateTime.Now.Date) { e.Row.Enabled = true;//row is editable } else { e.Row.Enabled = false;//row is not editable } } } 

by powerpack93 via /r/csharp

Leave a Reply