Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
bootstrap-datetimepicker only displays dd/mm/yyyy in production but work fine in dev. It should be displaying todays date, and letting me chose another date if required, but its stuck with the string "dd/mm/yyyy".. Its working fine in development though.. Here is my code.

C#
$(function () {
           $('#Date').datetimepicker({
               format: 'L',
               showClose: true,
               showClear: true,
               toolbarPlacement: 'top'
           });

<div class="form-group">
                                   @Html.LabelFor(model => model.Date, htmlAttributes: new { @class = "control-label col-md-2" })
                                   <div class="col-md-10">
                                       @Html.EditorFor(model => model.Date,
                                              new
                                              {
                                                  htmlAttributes = new
                                                  {
                                                      @class = "form-control"
                                                  },
                                              })
                                       @Html.ValidationMessageFor(model => model.Date, "", new { @class = "text-danger" })
                                   </div>
                               </div
>

I have tried to set the default date in jquery using
defaultDate: '@DateTime.Now.ToShortDateString()',
and it works fine in dev, but in production it only displays dd/mm/yyyy.

Thanks in advance.
Posted
Updated 2-Jun-15 13:01pm
v2

Have you checked if the jquery datetimepicker plugin is referenced in production?
 
Share this answer
 
Comments
nebiam 3-Jun-15 0:34am    
its working and referenced in development, hence i'm assuming it would be in production? .. I have checked the jquery on the page in viewsource and it exists.
After hours of testing and frustration i've been able to figure this out.

It seems browsers that support HTML5 such Google Chrome render this input field with a date picker.

In order to correctly display the date, the value must be formatted as 2012-09-28...

I had to change my model to the following;

SQL
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime Date { get; set; }


And use the plugin to edit the appearance of the date to my specific locale (dd/MM/yyyy).
 
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