0

I have a website where I am implementing datepickers, the site is for uploading school tasks, then I have a datepicker for the date on which it was commissioned (homeWorkDate) and another for the date that it should be delivered (reviewDate). The detail is more noticeable when you want to edit a task, at the time of loading the dates it always takes as reference today and not its date (baseDate).

I have tried with defaultDate and setDate

function setCalendarsDate(baseDate, homeWorkDate, reviewDate) {
    $("#fmt_d")
        .datepicker({
            defaultDate: baseDate,
            maxDate: homeWorkDate
        })
        .datepicker("setDate", homeWorkDate)

    $("#fmt_e")
        .datepicker({
            defaultDate: baseDate,
            minDate: reviewDate
        })
        .datepicker("setDate", reviewDate)
}
Domingo
  • 1
  • 1
  • 1
    Hey Domingo. Thank you for including your question in Spanish *and* English. However, as StackOverflow is specifically an English website, please consider removing the Spanish portion and translating the title. If you prefer to ask your question in Spanish, you can use [*Stack Overflow en español*](https://es.stackoverflow.com/) instead. – Tyler Roper Jul 15 '19 at 19:44
  • 1
    Did you tried `minDate` for setting starting date. For more details check here https://api.jqueryui.com/datepicker/ – Ankur Jul 16 '19 at 04:10
  • Not js expert, by any means but have you tried ` $("#fmt_d").datepicker("setDate", reviewDate)` ? – stefgosselin Jul 16 '19 at 04:13
  • @Ankur minDate is for the earliest date accepted by the textfield. – stefgosselin Jul 16 '19 at 04:16
  • Can you show the date formats which you are assigning in setDate function call? – Ankur Jul 16 '19 at 04:19
  • @stefgosselin Sorry I translated bad my code – Domingo Jul 16 '19 at 05:29
  • have you tried it?? [date-picker](https://stackoverflow.com/a/1328040/7709509) – Serajush Salekin Jul 16 '19 at 05:41
  • Thanks guys, it works, I just had to use **destroy** – Domingo Jul 16 '19 at 05:47

1 Answers1

0

Ok, I think this may help, credit to https://stackoverflow.com/a/751843/604259

Seems you may need to pass an object as second parameter.

$('#dateselector').datepicker("setDate", new Date(2008,9,03) );

Good-luck

stefgosselin
  • 8,822
  • 5
  • 39
  • 64
  • Not necessary to pass date object. Right format will work too. https://api.jqueryui.com/datepicker/#method-setDate – Ankur Jul 16 '19 at 04:21