I'm trying to compare 2 dates. If the date received is before the current day (Today) I have to delete the attribute @availabilityBeginDate
but if the date received is after the current day I have to save it. I'm writing it in CoffeeScript.
I want to do that with Moment.js and diff
. Here is the code I've tried but it doesn't work and I can't figure out why.
if (moment(moment(getCurrentDate()).diff(@availabilityBeginDate)).format("DD MMMM YYYY") < 0)
delete @availabilityBeginDate
Here is the getCurrentDate
method :
getCurrentDate:() ->
today = new Date
dd = today.getDate()
mm = today.getMonth() + 1
yyyy = today.getFullYear()
if dd < 10
dd = '0' + dd
if mm < 10
mm = '0' + mm
today = dd + ' ' + mm + ' ' + yyyy
return today
Here is how I save @availabilityBeginDate
:
bidDispoDetails.rows.push({label: 'Début', value: moment(@availabilityBeginDate).format("DD MMMM YYYY")}) if @availabilityBeginDate?