How to declare the datetimepicker value as null? This is my code.
dateTimePicker.Value.ToString() == string.Empty
could you please edit my code. because it is unrunnable.
How to declare the datetimepicker value as null? This is my code.
dateTimePicker.Value.ToString() == string.Empty
could you please edit my code. because it is unrunnable.
Because the datatype of DateTimePicker.Value
property is DateTime
, just checking whether the year is greater than 1900
would give only valid dates. You can change the year value to something more recent if your application demands so, but anything after 1900
is generally considered a valid date.
dateTimePicker.Value.Year > 1900
/* Here is a Method I wrote to validate expiry id ID in C# when selecting Date in DateTime Picker for Windows Forms. By demonguru18 aka techhowdy.com */
private bool isIDExpired()
{
DateTime objDateTime = DateTime.Parse(dtpIDExpiry.Value.ToString());
DateTime today = DateTime.Today;
int day = objDateTime.Day - today.Day;
int month = objDateTime.Month - today.Month;
int year = objDateTime.Year - today.Year;
if (day == 0 && month == 0 && year == 0)
{
MessageBox.Show("Your ID is Expiring Today. Please Provide new ID Expiry Date.");
return false;
}
else if (year < 0)
{
MessageBox.Show("Your ID has already Expired. Please Provide valid ID Expiry Date.");
return false;
}
else if (month < 0 && year < 0)
{
MessageBox.Show("Your ID has already Expired. Please Provide valid ID Expiry Date.");
return false;
}
else if (month == 0 && day < 0 && year == 0)
{
MessageBox.Show("Your ID has already Expired. Please Provide valid ID Expiry Date.");
return false;
}
return true;
}`