I'm using the Date-FNS library to get the difference between to dates in minutes. Why does minutesDifference return NaN? My goal is to get number of minutes between the given dates. Here is the link to the Date-FNS doc.
getDateTime: function () {
var now = new Date()
var year = now.getFullYear()
var month = now.getMonth()
var day = now.getDate()
var hour = now.getHours()
var minute = now.getMinutes()
var dateTime = year + ', ' + month + ', ' + day + ', ' + hour + ', ' + minute + ', 0'
var minutesDifference = differenceInMinutes(new Date(2018, 2, 30, 22, 55, 0), new Date(dateTime))
return minutesDifference
},
Your value of dateTime
is a string which is incorrect, you are passing 1 single param and not 6 different params to Date()
.
Just do
differenceInMinutes(new Date(2018, 2, 30, 22, 55, 0), new Date())
new Date
will take the current date/timestamp by default so you dont need to pass any params to it.
Please refer the docs: Date
- JavaScript | MDN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With