I have datetimepicker tool that is used for employee birth date entry and I want to check if the user forget to enter the valid birth date and left the datetimepicker on the current date ,so he'll get an alert message.
I've tried to write this code in ValueChanged event but it didn't worked as I wished ... any help
if (empRegBdatePicker.Value == DateTime.Today)
{
MessageBox.Show("Please enter a valid birth date of an employee");
empRegBdatePicker.Focus();
}
If you want to check just date, you can try this:
if(empRegBdatePicker.Value.Date == DateTime.Now.Date)
{
//birthdate is today
}
Just simply write
if(empRegBdatePicker < Today)
{
//birthdate is in past
}
Also, perform this validation before any save operations instead of some value changed events.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.