-1

Let's say I have a constant date of "March 1, 2016" (MMMM dd, yyyy) format. Is there any simple way to determine that my selected date in a DateTimePicker is greater than, less than or equal to the constant date?

doppelgreener
  • 4,809
  • 10
  • 46
  • 63
Jet Seighart
  • 29
  • 1
  • 6
  • 1
    _"Is there any simplier way"_ simpler than what? – Tim Schmelter Oct 12 '16 at 14:28
  • 1
    DateTime.ParseExact the constant date string to get a date variable then compare as you would any other two date variables. – Alex K. Oct 12 '16 at 14:29
  • 1
    Can't get any simpler than **CompareTo** https://msdn.microsoft.com/en-us/library/5ata5aya(v=vs.110).aspx – Innat3 Oct 12 '16 at 14:29
  • 1
    This could be a duplicate of http://stackoverflow.com/questions/25663033/how-to-compare-two-datetimepicker-values-in-c-sharp – KingPojo Oct 12 '16 at 14:35

2 Answers2

4

Simple enough ?

var fixedDate = new DateTime(2016, 3, 1);
if (myDateTimePicker.Value >= fixedDate) {
    ....
}
Ralf Bönning
  • 14,515
  • 5
  • 49
  • 67
1

Hope this helps:

My date picker is from WPF for example:

DateTime dt = new DateTime(1990, 06, 21);
DateTime selectedDate = (DateTime)((System.Windows.Controls.DatePicker)(sender)).SelectedDate;
if(dt >= selectedDate)
{
}