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

  • Home
  • SEARCH
  • 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 7785003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:11:09+00:00 2026-06-01T20:11:09+00:00

I have datetime input in my ASP.NET MVC3 app: <div class=editor-field> @Html.EditorFor(model => model.Article.PublishedDate)

  • 0

I have datetime input in my ASP.NET MVC3 app:

<div class="editor-field">
    @Html.EditorFor(model => model.Article.PublishedDate)
    @Html.ValidationMessageFor(model => model.Article.PublishedDate)
</div>

In Opera it makes special input for date and time but when I edit my model it´s empty and I want to set it to value. In other browsers it´s regular textbox and there is datetime set. Code which is generated thanks that code is:

<input class="text-box single-line" data-val="true" data-val-required="Publish date is required" id="Article_PublishedDate" name="Article.PublishedDate" type="datetime" value="30.3.2012 10:00:00" data-default-value=""/>

How can I fix it and set datetime in Opera too?

  • 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-01T20:11:10+00:00Added an answer on June 1, 2026 at 8:11 pm

    You need to format your datetime according to the RFC3339 standard

    HTML5 input datetime spec: http://dev.w3.org/html5/markup/input.datetime.html

    So your value needs to be formated something like this:

    <input ... type="datetime" value="2012-03-30T10:00:00" ... />
    

    To format a date as RFC3339 you can call:

    DateTime.ToString("yyyy-MM-ddThh:mm:ssZ");
    

    You can accomplish this by adding a DisplayFormatAttribute to you Article.PublishedDate:

    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-ddThh:mm:ssZ}")]
    public DateTime PublishedDate { get; set; }
    

    Problem now (at least for me) is that the property now always stays formated like this. You could use an EditorFor Template for this:

    @model DateTime?
    
    @{
        var attributes = new Dictionary<string, object>();
    
        attributes.Add("type", "datetime");
    
        attributes.Add("class", "text-box single-line");
    
        //since this is a constraint, IsRequired and other constraints 
        //won't necessarily apply in the browser, but in case script 
        //turns off readonly we want the constraints passed
        if (ViewData.ModelMetadata.IsReadOnly)
        {
            attributes.Add("readonly", "readonly");
        }
    
        if (ViewData.ModelMetadata.IsRequired)
        {
            attributes.Add("required", "required");
        }
    }
    @Html.TextBox("", Model.HasValue ? Model.Value.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ssZ") : String.Empty, attributes)
    

    Based on DateTime.cshtml

    And for local dates:

    @model DateTime?
    @{
      var attributes = new Dictionary<string, object>();
    
      attributes.Add("type", "datetime-local");
      attributes.Add("class", "text-box single-line");
    
      if (ViewData.ModelMetadata.IsRequired)
      {
        attributes.Add("required", "required");
      }
    }
    @Html.TextBox("", Model.HasValue ? Model.Value.ToLocalTime().ToString("yyyy-MM-ddTHH:mm:ss") : String.Empty, attributes)
    

    Based on DateTime-Local.cshtml

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

Sidebar

Related Questions

I have created this editor template: @model DateTime? @using MyMvcApp.Properties <div id=dateTimePicker_@(ViewData.ModelMetadata.PropertyName)> <script type=text/javascript
I have a string 12012009 input by the user in ASP.NET MVC application. I
I'm working on an asp.net MVC application. I have a class that wraps a
I have some inputs with OnBlur event handlers something like <input name=abc tabIndex=5 class=datetime
I have a asp.net textbox for date input, I use regular expression to let
I'm currently toying with asp.net mvc3 and have a question with respect to models
I created my first MVC application in ASP.NET today. I have a datetime column
I have a DateTime class and wish to display it according to some format...
I have a DATETIME field. I would like to select all the records that
I have a DateTime field in SQL Server for some products expiration (ExpirationDate). I

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.