Get the days until the end of the month with the help of the moment. Js

I want to show or hide the link depending on whether less than a month is left in the month using moment.js, but I'm not sure if this is the right way.

Currently, I ...

if (moment().endOf('month')<=(13, 'days'))
{
    //do link stuff here
}

... but I don't think this is the right way to do this. It does nothing anyway. Can anyone give me any directions? Thanks in advance.

+4
source share
2 answers

You can do something like this:

var a = moment().endOf('month');
var b = moment().today;

if(a.diff(b, 'days') <= 13)
{
    //do something
}
+5
source

If you are looking for a simple version of javascript, I wrote this function:

function getMonthDaysLeft(){
    date = new Date();
    return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate() - date.getDate();
}
+1
source

All Articles