warkanix
warkanix

Reputation: 13

xamarin android DatePickerDialog set mini date

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

Answers (3)

jace
jace

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

B. Mak
B. Mak

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

user5537890
user5537890

Reputation:

Try changing the mindate to date now?

dateTimePicker1.MinDate = DateTime.Now;

Something like that should work. :)

Upvotes: 0

Related Questions