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

86
Vistas
Jquery Datepicker Set Value From String

I am getting a string date from cookie which returns like this format 2017-11-16. My datepicker dateformat is D, M d, yy e.g Thu, Apr 27, 2017.

if I just set it as $("#m_checkin").datepicker().datepicker("setDate", "2017-11-16"); datepicker functions stop working and it just set 2017-11-16 as an input value. How can I format my date to my datepicker dateformat?

https://jsfiddle.net/n6dokkty/

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

You need to parse date before set date to particular format.
You can see here: https://jsfiddle.net/r1nm5h7k/

$( "#datepicker" ).datepicker({dateFormat: "DD, d MM, yy"});
$( "#datepicker" ).datepicker("setDate", $.datepicker.parseDate( "yy-mm-dd", "2017-11-16" ));

ref : https://api.jqueryui.com/datepicker/#utility-formatDate

about 4 years ago · Santiago Trujillo Denunciar

0

You could look into momentjs, which is a javascript date/time library. With that, you can easily convert between dates of different format.

string newDate = moment(currentDate, currentFormatString).format(newFormatString)

about 4 years ago · Santiago Trujillo Denunciar

0

You have to setDate with Date object instead of string (to avoid date format issues like you face currently).

So you have to change your code like below:

$("#m_checkin").datepicker().datepicker("setDate", new Date(2017,11,16));
about 4 years ago · Santiago Trujillo 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