USER
USER

Reputation: 781

Formatting input type date in vue.js

I use bootstrap-vue, which includes an input type of date.

When I write some number, the default format is yyyyyy-mm-dd.

I want to change that format to yyyy-mm-dd.

Upvotes: 7

Views: 25784

Answers (3)

Ravi Ram
Ravi Ram

Reputation: 24488

I am using moment.js

data:{
        startDate: moment().format("YYYY-MM-DD"),
        endDate: moment().format("YYYY-MM-DD"),
    }

HTML

<input type="date" class="form-control" v-model="startDate"> {{startDate}}
<input type="date" class="form-control" v-model="endDate"> {{endDate}}

Upvotes: 2

L&#233;o
L&#233;o

Reputation: 1

Try this :

<input type="date" v-model="moment(mydate).format('YYYY-MM-DD')" v-on:input="mydate = moment($event.target.value).toDate()"/>

Upvotes: -1

Ohgodwhy
Ohgodwhy

Reputation: 50798

use a formatter:

:formatter="format"

Declare how the value should be formatted within this function:

format(value, event) {
    return moment(value).format('YYYY-MM-DD')
}

As an example using the momentjs library.

Upvotes: 11

Related Questions