Search code examples
javascriptvue.jsdatepickerbuefy

How does Buefy datepicker output 'yyyy-MM-dd' string?


I have a date picker in my Buefy form in my Vue application that is suppose to populates a table from an api call. I populate the api call with the Buefy form. the api call needs the format 'yyyy-MM-dd' but i receive a totally different format from buefy v-model="startdate".

I am passing the startdate into the api call as of ${this.startdate}. I need it to be a string in the format 'yyyy-MM-dd'. example date string: '2019-04-23'

how do I achieve this? is it possible with the date-parser property of buefy datepicker ? if so what would the function be?

so far I have :date-parser="dateParser" in the b-datepicker tag

and in the methods i have

dateParser(date) {
      new Date.parse(date);
    }

whats next?


Solution

  • So as of Walter's reply, I used the logic below to retrieve my answer:

    let myDate = new Date(Date.parse(this.startdate));
          let realDate =
            myDate.getFullYear() +
            "-" +
            ("0" + (myDate.getMonth() + 1)).slice(-2) +
            "-" +
            ("0" + myDate.getDate()).slice(-2);