Reputation: 13
I'm using DatePickerDialog and i want to hide every date before today. I can hide previous month and year using this code:
dialog.DatePicker.MinDate = new Java.Util.Date().Time - 1000;
But it's not working like i want. Days between 1st of june and today are disabled (gray) but we still can click on them and dismiss the dialog by clicking on the positive button.
Does someone has a solution to realy disabled them ? or at least avoid dismiss the dialog?
Upvotes: 1
Views: 771
Reputation: 1674
//for lesser than today
dialog.DatePicker.MinDate = Java.Lang.JavaSystem.CurrentTimeMillis();
//for greater than today
dialog.DatePicker.MaxDate = Java.Lang.JavaSystem.CurrentTimeMillis();
This solved mine :)
Upvotes: 0
Reputation: 11
You need to give MinDate the number of milliseconds between your minimum date (in your case today) and January 1st 1970, so:
dialog.DatePicker.MinDate = (long)(DateTime.Today.Date - new DateTime(1970, 1, 1)).TotalMilliseconds;
This should prevent users from selecting any earlier dates.
Upvotes: 1
Reputation:
Try changing the mindate to date now?
dateTimePicker1.MinDate = DateTime.Now;
Something like that should work. :)
Upvotes: 0