How to compare date time without time portion in C#

Viewed 13797

i tried this way but getting error. here is my code.

protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
    DateTime _dateJoin = DateTime.ParseExact(value.ToString(), "MM/dd/yyyy", null);
    DateTime _CurDate = DateTime.ParseExact(DateTime.Now.ToString(), "MM/dd/yyyy", null);

    int cmp = _dateJoin.CompareTo(_CurDate);
    if (cmp > 0)
    {
        return ValidationResult.Success;
    }
    else if (cmp < 0)
    {
        return new ValidationResult(ErrorMessage);
    }
    else
    {
        return ValidationResult.Success;
    }
}

the value variable has valid date with time portion too. thanks

2 Answers
Related