Click here to Skip to main content
15,884,078 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hi to all,
In my model i have date format but now i want to change dd/mm/yyyy .how to change if i change this format(dd/mm/yyyy) using datepicker. i got error enter valid date here i use all the methods like costume validation,globalize,date format all i used but i got an error.how to resolve this error.
Posted
Comments
DamithSL 29-Nov-14 3:25am    
how you set the format in your code?
JOTHI KUMAR Member 10918227 29-Nov-14 5:47am    
i set dd:mm:yyyy
JOTHI KUMAR Member 10918227 29-Nov-14 5:47am    
model:-
[Required]
[Column(TypeName = "date")]
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
// [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? Posting_Date { get; set; }

View:-
<div class="col-md-8">
@Html.TextBoxFor(model => model.Posting_Date, new { @Value = DateTime.Now.ToString("dd/MM/yyyy"), @class = "form-control control-text datePicker", @id = "IssueDate" })
@Html.ValidationMessageFor(model => model.Posting_Date)
</div>
JOTHI KUMAR Member 10918227 29-Nov-14 4:44am    
model:-
[Required]
[Column(TypeName = "date")]
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
// [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? Posting_Date { get; set; }

View:-
<div class="col-md-8">
@Html.TextBoxFor(model => model.Posting_Date, new { @Value = DateTime.Now.ToString("dd/MM/yyyy"), @class = "form-control control-text datePicker", @id = "IssueDate" })
@Html.ValidationMessageFor(model => model.Posting_Date)
</div>
Maciej Los 29-Nov-14 9:34am    
Date has nothing to do with its format! Date is just a date.

1 solution

Hi If you are using the date-picker then you can set the date format as per your requirement there.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900