I'm currently working on Vue Datatable and I have a specific requirement to search for records between two dates. I am using the moment.js library and the inBetween
function to achieve this. Strangely, when I hardcode the dates, the function returns the correct result. However, when I input dates of type date, the function always seems to return false
. Can someone please assist me with this issue?
var fDate = moment(this.startDate).format("DD-MM-YYYY")
var lDate = moment(this.endDate).format("DD-MM-YYYY")
tab = tab.filter(function (row) {
var compareDate = moment(row["createdAt"]).format("DD-MM-YYYY")
var comparison = moment(compareDate).isBetween(fDate, lDate) // always returns false
var t = moment("2010-10-20").isBetween("2010-10-19", "2010-10-25") //returns true
console.log(compareDate, fDate, lDate, comparison, t)
})
You can view the demo here: https://codesandbox.io/s/inspiring-river-kg4bs?file=/src/App.vue:281-294