7

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.

3 Answers 3

11

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.

Sign up to request clarification or add additional context in comments.

2 Comments

formatter option works after typing all text. if I type 20190314 it returns 201903-14- .
It should not matter the format at which you type. The purpose of using a data library in the formatter is to take an arbitrary string an attempt to convert it to the proper case. If it's not proper, you should display . an error and let the user know.
1

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}}

Comments

-1

Try this :

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.