Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
Change Date format in datepicker

I have a question about changing the date format to dd/mm/yyyy. I want the default date to be 09-01-2022. But below the code doesn't work to change dd/mm/yyyy.

var today = "Wed Jan 09 2022 13:01:18 GMT+0800 (Malaysia Time)";
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;
<div class="col-xs-12 col-md-2">
<label>Date&nbsp;:</label>
<input type="date" class="form-control" id="date_of_daily" name="date_of_daily" value="2022-01-09" title="Date of daily" min="2022-01-09" max="2022-01-11">
</div>

Actually I want the result like below picture:

output

Hope someone can guide me on how to solve this problem. Thanks.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can try it with :

var today = "Wed Jan 09 2022 13:01:18 GMT+0800 (Malaysia Time)";

function convertDate(inputFormat) {
  function pad(s) { return (s < 10) ? '0' + s : s; }
  var d = new Date(inputFormat)
  return [pad(d.getDate()), pad(d.getMonth()+1), d.getFullYear()].join('/')
}

console.log(convertDate(today))

$(function() {
  $("#date_of_daily").datepicker({
    dateFormat: "dd/mm/yy",
    minDate: 0,
    maxDate: "+2D +0M",
    showAnim: "slideDown"
  });
});
<link rel="stylesheet" href="https://code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>
<div class="col-xs-12 col-md-2">
  <label>Date&nbsp;:</label>
  <input type="text" class="form-control" id="date_of_daily" name="date_of_daily" size="30" value="09/01/2022" title="Date of daily" min="2022-01-09" max="2022-01-11">
</div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

I hope the below answers your question...You need to basically parse the string today to convert it to a date before calling functions of Date on it like getDay etc...

var today = "Wed Jan 09 2022 13:01:18 GMT+0800 (Malaysia Time)";
var dd = String(Date.parse(today)).padStart(2, '0');
var mm = String(new Date(Date.parse(today)).getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = new Date(Date.parse(today)).getFullYear();
today = mm + '/' + dd + '/' + yyyy;
<div class="col-xs-12 col-md-2">
<label>Date&nbsp;:</label>
<input type="date" class="form-control" id="date_of_daily" name="date_of_daily" value="2022-01-09" title="Date of daily" min="2022-01-09" max="2022-01-11">
</div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda