3

I am trying to keep my calendar displays the date which every the user picks. and now my"{{date}}" is in the format like 2016-01-11. Buy it is keep showing one day before the day I picked. I want it displays like mm/dd/yyyy.

I am thinking that I have to convert my date format from 2016-01-11 to 01/11/2016 but how to accomplish that ?

$(function(){
          $("#datepicker").datepicker({
                   onSelect:function(dateText, inst){
                          var day = $.datepciker.formatDate("yy-mm-dd",new Date(dateText));
                          $(location).attr("href","/report_date/" + day + "/");
                   }
          })
          $("#datepicker").datepicker("setDate", new Date("{{date}}"));
})

All my directories are named like 2016-10-11, thats why i am using yy-mm-dd

‌‌R‌‌‌.
  • 2,818
  • 26
  • 37
Mr HoHo
  • 33
  • 4

2 Answers2

0
$(function(){
    $("#datepicker").datepicker({
        onSelect:function(dateText, inst){
            var day = $.datepciker.formatDate("yy-mm-dd",new Date(dateText));
            $(location).attr("href","/report_date/" + day + "/");
        }
    })
    var dateNew = $('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' }).val();
    $("#datepicker").datepicker("setDate", dateNew);
})
LORDTEK
  • 137
  • 11
0

i figured it out...

' var date = "{{date}}";
  var year = date.substring(0,4);
  var month = date.substring(5,7);
  var day = date.substring(8,10);
  $("#datepicker").datepicker("setDate", month + "/" + day + "/" + year):
Student.
  • 88
  • 1
  • 1
  • 8