I have a ViewModel for my MVC4 Prject containing two DateTime properties:
[Required]
[DataType(DataType.Date)]
public DateTime RentDate { get; set; }
[Required]
If you're using .Net Framework 3.0 or higher you could do it as a class extension...
///
/// Determines if a DateTime falls before another DateTime (inclusive)
///
/// The DateTime being tested
/// The DateTime used for the comparison
/// bool
public static bool isBefore(this DateTime dt, DateTime compare)
{
return dt.Ticks <= compare.Ticks;
}
///
/// Determines if a DateTime falls after another DateTime (inclusive)
///
/// The DateTime being tested
/// The DateTime used for the comparison
/// bool
public static bool isAfter(this DateTime dt, DateTime compare)
{
return dt.Ticks >= compare.Ticks;
}