Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8133835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:46:42+00:00 2026-06-06T09:46:42+00:00

I have the following field : @Html.TextBoxFor(model => model.Patient.dateOfBirth, new { id = datepicker,

  • 0

I have the following field :

@Html.TextBoxFor(model => model.Patient.dateOfBirth, new { id = "datepicker", @class = "double text white" })

It is a DateTime field that has the following metadata definition:

 [Required(ErrorMessage = "Date Of Birth is required")]
 [DisplayFormat(DataFormatString = "{0:dd MMM yyyy}")]
 public DateTime dateOfBirth;

The issue is that i need it to show the DOB as d/m/y but as a datetime cause i am using a datepicker that needs the value to remain DateTime.

Date picker returns a value that has the dd/mm/yy format. (.ToShortDateString() cant save me this time )

I’ve tried Darin Dimitrov Answers from here and here , but unless I am a complete moron those don’t really work for me.


Later Edit:

I have managed to find the solution for this and wanted to share it with whomever needs it from now on.

 @Html.HiddenFor(model => model.DOBirth, new { id = "shortDate", @class = "double text white" })

 @Html.TextBox(" ", Model != null ? Model.dateOfBirth.Value.ToShortDateString() : string.Empty, new { id = "datepicker", @class = "double text white" })

And use the following Jquery :

 $('#datepicker').datepicker({
            changeMonth: true,
            changeYear: true,
            inline: true,
            onSelect: function (dateText, inst) { CalculateAge(dateText); } //an extra method
        });

Store the value you get into your hidden field ( via Jquery through the id of the hidden field “shortDate”) and thus you can send the value back to the controller

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:46:44+00:00Added an answer on June 6, 2026 at 9:46 am

    I’ve tried Darin Dimitrov Answers from here and here , but unless I am
    a complete moron those don’t really work for me.

    That’s because you forgot to add ApplyFormatInEditMode = true in your [DisplayFormat] attribute:

    [Required(ErrorMessage = "Date Of Birth is required")]
    [DisplayFormat(DataFormatString = "{0:dd MMM yyyy}", ApplyFormatInEditMode = true)]
    public DateTime dateOfBirth;
    

    and then:

    @Html.EditorFor(model => model.Patient.dateOfBirth)
    

    Another possibility is to write a custom editor template for a date picker:

    [Required(ErrorMessage = "Date Of Birth is required")]
    [DisplayFormat(DataFormatString = "{0:dd MMM yyyy}", ApplyFormatInEditMode = true)]
    [UIHint("DatePicker")]
    public DateTime dateOfBirth;
    

    and inside ~/Views/Shared/EditorTemplates/DatePicker.cshtml:

    @Html.TextBox(
        "", 
        ViewData.TemplateInfo.FormattedModelValue, 
        new { @class = "double text white datepicker" }
    )
    

    and inside your view:

    @Html.EditorFor(model => model.Patient.dateOfBirth)
    

    Notice that I have applied the datepicker class instead of using an id to aviod conflicts if you have more than one DateTime field. You will need to adapt your selector accordingly: $('.datepicker').datepicker(); instead of $('#datepicker').datepicker(); that you are currently using.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: <div class=editor-field> <%: Html.TextBoxFor(model => model.MyId) %> <%: Html.ValidationMessageFor(model
I have the following HTML: <table> <tr class=row> <td class=field> <input type=text /> </td>
In my view I have the following: @Html.TextBoxFor(model => model.EndDate) When the code and
I have following html. <fieldset id=fieldset-step_3> <input type=text value=2 id=rule_form-lead_time name=rule_form[lead_time]> <select class=w50 id=rule_form-operator
I have following HTML code. writer input field is text filed. but I want
I have the following html: <label class=description>Label Text</label><input type=password /> And the css styles
I have the following select field and based on whether the class .show-x-trend or
I have the following text contained within a field in my DB: [quote:5a7b87febe=mr smith]This
I have following code in a html form <select name=category class=input onchange=ShowTB(this,'suggest');> <option value=0
I have the following HTML scenario: <div> <input id=txt0 type=text /><input type=checkbox id=chk0 /></div>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.