I have a problem with my project ,it is about Human Resources Information System
it has a feature to upload Schedule using excel file ,but in my application
the format of date should be like this
11/30/2019
Month/Date/Year
but in some case user input in wrong format ,
for example like this
30/30/2019
Date/Month/Format
so i need a validation, i give a message for user if the date is invalid format
the message like this
Error Line Description
Line 2 43783 Incorret Format
i just get stuck and error in condition user input right format but system still validate it as wrong format
What I have tried:
How can i solve this
this is my code
if (DateTime.TryParseExact(schedule_date, "MM-dd-yyyy", new CultureInfo("en-US"), DateTimeStyles.None, out d))
{count += 0;
string labelmonth = ddlTest.SelectedValue.ToString()
string employee_id = worksheet.Cells[i, 1].Value.ToString();
string user = Session["LogedUserID"].ToString();
bool validatemonth = ddlTest.SelectedValue.ToString() ==
DateTime.Parse(worksheet.Cells[i, 3].Value.ToString()).ToString("MM");
if (validatemonth.Equals(false))
{ count += 1;
cell1.Text = "Pada Baris ke " + i + " ";
+ Convert.ToDateTime(schedule_date).ToString("MM/dd/yyyy");
cell2.Text = "Bulan Tidak Sesuai ";
row.Cells.Add(cell1);
row.Cells.Add(cell2);
mytable.Rows.Add(row);
}
}
else
{
count += 1;
cell1.Text = "Pada baris Ke " + i + " " + Convert.ToString(schedule_date);
cell2.Text = "Format Tanggal Salah";
row.Cells.Add(cell1);
row.Cells.Add(cell2);
mytable.Rows.Add(row);
}
}