Sidney Sousa
Sidney Sousa

Reputation: 3604

Date format showing different using jquery

I wanna display the dates on my WordPress site like the Picture, where the months with long names come abbreviated. enter image description here

My jquery looks like this:

jQuery(document).ready( function($){

    var txtFromDate, txtToDate;
  $("#txtFrom").datepicker({
    numberOfMonths: 1,
    onSelect: function(selected) {
      txtFromDate = selected;
      var dt = new Date(selected);
      dt.setDate(dt.getDate() + 1);
      $("#txtTo").datepicker("option", "minDate", dt);
    }
  });
  $("#txtTo").datepicker({
    numberOfMonths: 1,
    onSelect: function(selected) {
      txtToDate = selected;
      var dt = new Date(selected);
      dt.setDate(dt.getDate() - 1);
      $("#txtFrom").datepicker("option", "maxDate", dt);
    }
  });

  $('a#atributo').click(function() {
    // var link = day_1+month_1+year;
     var monthNames = [
        "Jan", "Feb", "Mar",
        "Apr", "May", "Jun", "Jul",
        "Aug", "Sep", "Oct",
        "Nov", "Dec"
      ];

    var date1 = $("#txtFrom").datepicker('getDate'),
        day_1  = date1.getDate(),  
        month_1 = date1.getMonth() + 1,              
        year_1 =  date1.getFullYear();

    var date2 = $("#txtTo").datepicker('getDate'),
        day_2  = date2.getDate(),  
        month_2 = date2.getMonth() + 1,              
        year_2 =  date2.getFullYear(); 

    var where = $('#selection :selected').text();
    var people = $('#search-pax :selected').val();

    $(this).attr("href", "http://www.lekkeslaap.co.za/akkommodasie-in/"+where+"?q="+where+"&start="+day_1+"+"+monthNames[month_1]+"+"+year_1+'&end='+day_2+'+'+monthNames[month_2]+'+'+year_2+'&pax='+people);
  });
});

And for now when I view the site it looks like this:

enter image description here

How can I change the date format?

I found this in the api documentation but I am struggling to implement

Hope you can help and here my full pen for it

Upvotes: 1

Views: 76

Answers (2)

Ragmah
Ragmah

Reputation: 411

After the comma where you have "numberOfMonths:1," add this:

dateFormat: "d/M/yy"

You are welcome to change the slash by dash or nothing

Upvotes: 1

NetVicious
NetVicious

Reputation: 4045

You need to add inside the datepicker options the dateFormat option:

dateFormat: "d M yy"

Upvotes: 0

Related Questions