How to change the format of the day in javascript?

Asked

Viewed 38 times

1

Good person, the scene is that I have here the script that makes that when making a reservation, you can not select the day of yesterday, and such . ,.. but when I see the date appears in the format MM-DD-YYYY , and I don’t know how to make it stay DD-MM-YYYY

//Script para que só se possa selecionar a data de hoje
$(document).ready(function(){
    $("#StartDate").datepicker({
        minDate: 0,
        maxDate: "+60D",
        numberOfMonths: 1,
        onSelect: function(selected) {
          $("#txtToDate").datepicker.formatDate("dd-mm-yy","option","minDate", selected)

        }
    });
    //Script para que só se possa selecionar o dia de amanhã e os restantes
    $('#EndDate').datepicker({
        minDate: 0,
        maxDate:"+60D",
        numberOfMonths: 2,
        onSelect: function(selected) {
           $("#StartDate").datepicker("option","maxDate", selected)
        }
    }); 
});
  • 1

    Good afternoon, use relevant question tags and not your entire project.

  • Related : http://answall.com/questions/6526/como-formatr-data-no-javascript ?

2 answers

1

The datepicker API has an option for this. You have to pass the configuration object dateFormat: 'dd-mm-yy'. In your case the code could be:

$("#StartDate").datepicker({
    minDate: 0,
    maxDate: "+60D",
    numberOfMonths: 1,
    dateFormat: 'dd-mm-yy' // <-----------
    // etc...

Example: http://jsfiddle.net/m4qovgkx/

  • 1

    Thank you very much. I tried to put dateformat with various functions, I did not think it was so easy. thanks very much

  • @Good Odacil, glad to help too.

  • If it’s not too much to ask, there’s another way to contact him ? I’d really like you to help me. since I’ve been trying to finish a project for 3 months. I’d really appreciate it if you could. thank you

  • 1

    @All Stackoverflow’s idea is to create together content that can help others. It may sound strange but I have time to help here when I can but I don’t have time to commit to more projects. But keep asking here what you can’t do, always trying to solve the problem yourself before asking.

1

My friend, since we’re talking about the pattern pt-br, Besides the answer given by friend Sergio, I believe that the editions I made in the link below can help you a lot.
https://jsfiddle.net/m4qovgkx/1/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.