0

I have an asp:textbos with textmode="Date" which turns the textbox into a date picker, how can I block the future dates from the current date

1 Answer 1

2

Try using max attribute to restrict the future date to be selected.

<input type="date" max="2013-11-20" value="2013-11-20" />

You can set the current day by either of these way.
1. using code behind

dateInput.Attributes["max"] = DateTime.Now.ToString("yyyy-MM-dd");

2. using markup

<input type="date" max="<%= DateTime.Now.ToString("yyyy-MM-dd") %>" />

Yes but after this, you can still select the future date using up arrow, so we can put some css trick to hide that something like this

input[type=date]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    display: none;
}

Js Fiddle

Sign up to request clarification or add additional context in comments.

5 Comments

If that is the max date, which is today, how will I select future dates when it turns tomorrow
it worked fine, but it still accepts future dates when I click the up arrow on the date picker.
thanks for the update, where will i put the css trick? will i declare it as css class?
@JbMeris no need to declare it as class as I have use input selector so it will work without giving the class. You just need to put in css section.
i made it work already, thankyou very much for your update and help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.