1

I have created a database table with a DateTime column.

Datetime stored in db as 2013/06/21 00:00

Upon scaffolding, the datetime column auto displays to user in local format 21/06/2013 00:00 which is not what was specifically specified, but no real complaints.

Problem comes when editing the scaffolded column, it also displays to user in textbox in 21/06/2013 00:00 and not in format 2013/06/21 00:00

As such, datetime will always fail validation unless user manually converts to 2013/06/21 00:00

Have i done something wrong?

When scaffolding, I never asked it to display date in Local format. And if it is automatically going to display the date to local format, then surely it should automatically convert the date to international format???

How do I fix this issue?

1 Answer 1

1

Write this before the DateTime property of your class:

[DataType(DataType.DateTime)]

for example:

public partial class MyModel
{
    // something ...

    [DataType(DataType.DateTime)]
    public DateTime MyDateTime { get; set; }

    // something other ...
}
Sign up to request clarification or add additional context in comments.

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.