A
A
Andrej Sharapov2020-03-03 16:19:42
Vue.js
Andrej Sharapov, 2020-03-03 16:19:42

How to compare two dates in vuejs?

Good afternoon!
Tell me, is it really possible to compare dates if:

1. in data() {...} while outputting this:
isTodayDate: new Date().toISOString().slice(0, 10)returns the format 2020-03-03
All that I could ...

2. in JSON'e, the date format is String

list: [
        {
          ...,
          ...,
          dateend: "31.05.2018"
          ...,
        },
        {
          ...,
          ...,
          dateend: "03.04.2021"
          ...,
        },
        {
          ...,
          ...,
          dateend: "31.03.2018"
          ...,
        },
        {
          ...,
          ...,
          dateend: "31.03.2018"
          ...,
        }
      ]


You need to compare and make a filter with the condition that the date in the json file is less than the current one.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-03-03
@Madeas

data: () => ({
  now: Date.now(),
  ...
}),
computed: {
  filteredList() {
    return this.list.filter(n => this.parseDate(n.dateend) < this.now);
  },
  ...
},
methods: {
  parseDate: str => new Date(str.split('.').reverse().join('-')),
  ...
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question