Moment JS – check if a date is today or in the future

I am trying to use momentjs to check if a given date is today or in the future.

This is what I have so far:

<script type="text/javascript" src="http://momentjs.com/downloads/moment.min.js"></script>
<script type="text/javascript">

var SpecialToDate="31/01/2014"; // DD/MM/YYYY

var SpecialTo = moment(SpecialToDate, "DD/MM/YYYY");
if (moment().diff(SpecialTo) > 0) {
    alert('date is today or in future');
} else {
    alert('date is in the past');
}

</script>

The code is evaluating my date (31st of Jan 2014) as a date in past.

Any idea what I am doing wrong?

18 Answers
18

Leave a Comment