MVC Using Date for DateTime in HTML5 form

Hi:

I have a UserProfile class that includes a birthdate as follows


Open in new window


I would like to include that date in an html date input.  

When I made the type of the input "date", I got the nice native datepicker in Chrome.  However, got no data...

 <input class="form-control" id="DateOfBirth" name="DateOfBirth" type="date" value='@Model.UserProfile.DateOfBirth' required/>

Open in new window


I have tried converting  the DateOfBirth to a date in various ways - e.g.

<input class="form-control" id="DateOfBirth" name="DateOfBirth" type="datetime" value='@Model.UserProfile.DateOfBirth.Date' required/>

Open in new window

but no luck and the date shows up in the input as 10/9/1972 12:00:00 AM with no datepicker.

Any help in getting this to work greatly appreciated.

RBS
RBSAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
The format needs to be
yyyy-mm-dd

and nothing else
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RBSAuthor Commented:
Hi:

Great - thanks - it worked with one modification:  yyyy-mm-dd won't work for the month - it has to be yyyy-MM-dd - and nothing else :)

RBS
0
GaryCommented:
The format is a template - there is no actual 'mm'
0
RBSAuthor Commented:
Ok, I was using @Model.UserProfile.DateOfBirth.ToString("yyyy-MM-dd") and thought I had it working - but it is no more - how would you express this as a "template"?
0
GaryCommented:
I was talking about the template (how the date should look) for the input box not for how you format it in .net.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.