1

Problem: Change the Date input field from "mm/dd/yyyy" to "dd/mm/yyyy".

I already know how to change after i receive the date, but the problem is that when the client is typing the input is still receiving "mm/dd/yyyy".

My mongoose schema:

const schemaRegister = new mongoose.Schema({
  date: Date,
});

My input area:

 <b-form-input v-mask="'##/##/####'" v-model="date"></b-form-input>

My date formating (using momentsjs):

changeDateFormat() {
        let fixedDate = moment(this.registers[i].date).format("L");
        this.registers[i].date = fixedDate;
      }

I am displaying the 'fixedDate' on the table, but it doesn't help a lot because when the client is typing he thinks the first 2 slots are the days (dd), but in reality they are the month (mm). As a solution i thought of using the Date as a String but then it would make the verification very difficult.

3
  • 1
    check this answer stackoverflow.com/questions/57886089/… Commented Sep 18, 2019 at 12:03
  • The problem is not how i want to display the date, but when the client is typing. When he is typing (mm/dd/yyyy), he thinks he is actually typing (dd/mm/yyyy). Commented Sep 18, 2019 at 12:14
  • @incrediblenothing Since the mm and dd are the same length and integer types you will need to do some validation on your side to handle if they type it in the wrong order. Do a check if the first two digest exceed 12, or second set exceeds 31. You can provide a hint on the UI on the format expected? Or even a date picker to assist the user. if someone types in 10/10/2019 how will you handle the data? Commented Sep 19, 2019 at 17:55

2 Answers 2

0

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

just pass the parameters in the correct order, like this:

new Date(day, monthIndex, year);
Sign up to request clarification or add additional context in comments.

Comments

0

I wasn't using the 'momentsjs' correctly, first i needed to parse the input date by using

 let formatedDate = moment(this.date,"DD-MM-YYYY");

and then for displaying the date i should have used

let fixedDate = moment(this.registers.date).format("DD/MM/YYYY");

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.