0

QUESTIONS

Why is type="date" reformatting my date string?

(From what I have read type="date" writes string as YYYY-MM-DD but this still doen't seem to output what is expected).

How can type="date" be formatted to desired output?

(Type date is required for touchpad keyboards).


TYPE:TEXT

<asp:TextBox type="text" ID="txtDate" runat="Server" Text="13/02/2014"/>

OUTPUTS

13/02/2014

<input type="text" value="13/02/2014">

TYPE: DATE

<asp:TextBox type="date" ID="txtDate" runat="Server" Text="13/02/2014"/>

OUTPUTS

2/1/2015

<input type="text" value="2/1/2015">

10
  • Did you try using the date format as yyyy-mm-dd ? Commented Feb 13, 2014 at 16:01
  • @Amitd Yes no luck. Also just tried : Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "Date")).ToString("d") Commented Feb 13, 2014 at 16:17
  • 3
    It's going to be easier to tell what is being done to the HTML 5 date input if you show us the HTML 5 source instead of the ASP.NET source that generates it. Commented Feb 13, 2014 at 16:23
  • @Quentin see edits above. output shows no reason for this to occur. Commented Feb 13, 2014 at 16:38
  • 1
    @DreamTeK — Oooh, so the problem is that the ASP.NET isn't generating what you wanted? I thought you meant the browser was munging the date. Commented Feb 13, 2014 at 16:40

2 Answers 2

1

The HTML5 input date expects the date in the RFC3339 format:

yyyy-mm-dd

See this jsfiddle. It shows:

02/14/2014

for

<input type="date" value="2014-02-14" />
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks I already noted the standards are yyyy-mm-dd. But does this mean I cannot use type=date AND format the date to desired output?
No. Not according to the specs.
More thoughts on this?
Sorry Patrick I had to leave. Yes I now understand how it works and have added notes above.
@DreamTeK: Can I help you with anything more?
0

Why is type="date" reformatting my date string?

When using type="date" the date must be inserted in the format yyyy-mm-dd as per the specifications mentioned by Patrick below.


How can type="date" be formatted to desired output?

The date output will then be displayed to the user based on the users browser and their calendar settings.

e.g in my case I use UK calendar so if yyyy-mm-dd goes in dd-mm-yyyy will be displayed.

Comments

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.