Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!