0

I wonder if someone has stumbled upon this type of scenario before. Please tell me how you fixed it.

So, on my development PC, my date format is DD/MM/YYYY. It shows the same format when I "Run"(F5) the project and test stuff. However, when publishing to the web server and a user goes to the date, the format is in MM/DD/YYYY.

For your information: The settings on the Web Server are exactly the same as on the development PC. Both have the same region, the same dateTime format in Control Panel -> Region.

I do not code any funny regional settings in my code because it is just a dateTimePicker displaying a javascript calender from which the user chooses.

Code for reference: The datetimepicker:

       <script type="text/javascript">
                                $(document).ready(function() {
                                // Datepicker Popups calender to Choose date.
                                $(function() {
                                $("#datepicker_end").datepicker();
                                // Pass the user selected date format.
                                $("#format").change(function() {
                                    $("#datepicker_end").datepicker("option", "dateFormat", "dd-mm-yy");
                                });
                                });
                                });
                </script>


        <script type="text/javascript">
                                $(".date-pick").datepicker();
                                $(".date-pick").datepicker('setDate', new Date());
                                var now = new Date();
                                var day = ("0" + now.getDate()).slice(-2);
                                var month = ("0" + (now.getMonth() + 1)).slice(-2);
                                var today = now.getFullYear()+"-"+(month)+"-"+(day) ;
                                $('#datepicker_start').datepicker({ dateFormat: 'dd-mm-yyyy' }).val(today);
                                $('#datepicker_start').show();
                </script>

That's everything I can give you. Tried googling multiple things but can't find a solution. Thanks.

EDIT Okay, I did the formatting piece as Frederico suggested. No luck. Anyone else have some other ideas/suggestions??

fl13
  • 57
  • 1
  • 1
  • 12

2 Answers2

0

Sure, you are not the only one, check this:

jQuery UI DatePicker - Change Date Format

the solution is:

var date = $('#datepicker').datepicker({ dateFormat: 'DD/MM/YYYY' }).val();

for making it fixed. The format may change depending on settings on your browser.

<script type="text/javascript">
    $(document).ready(function() {
      // Datepicker Popups calender to Choose date.
      $(function() {                                        
        $("#datepicker_start").datepicker();
        // Pass the user selected date format.
        $("#format").change(function() {
          $("#datepicker_start").datepicker({ dateFormat: 'DD/MM/YYYY' });
        });
      });
   });
</script>
  • Okay, this I tried. I did it the exact way and still formats the date as MM/DD/YYYY. – fl13 Jun 08 '17 at 10:54
0

So this was the solution I came across. Thanks for the one input. How to change date format (MM/DD/YY) to (YYYY-MM-DD) in date picker

Changed my code to match this in a way and it worked.

 $(function(){
    $("#to").datepicker({ dateFormat: 'yy-mm-dd' });
    $("#from").datepicker({ dateFormat: 'yy-mm-dd' }).bind("change",function(){
        var minValue = $(this).val();
        minValue = $.datepicker.parseDate("yy-mm-dd", minValue);
        minValue.setDate(minValue.getDate()+1);
        $("#to").datepicker( "option", "minDate", minValue );
    })
});
fl13
  • 57
  • 1
  • 1
  • 12