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?
Asked
Active
Viewed 2,518 times
-1
-
1_"Is there any simplier way"_ simpler than what? – Tim Schmelter Oct 12 '16 at 14:28
-
1DateTime.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
-
1Can'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
-
1This 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 Answers
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)
{
}

user1727883
- 56
- 5