I am trying to save date from C# to SQL Server. First want to display Date format as dd/MM/yyyy to the user. then after selecting the date on Winforms screen. I want to save it to database. If I remove datetimePicker1.CustomFormat
line in the code it is saving fine to the database. But I want to display the date format as dd/MM//yyyy. How to solve this?
I'm getting this error:
SqlDateTime overflow.Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
Code:
//c#
DateTime fromDate;
public void SetMyCustomFormat()
{
// Set the Format type and the CustomFormat string.
//dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "dd/MM/yyyy";
DateTime.TryParse(dateTimePicker1.Text, out fromDate);
fromDate = fromDate.Date;
}