Custom Security Conditions - moment.js

Hello, I am finishing a custom security condition and what I am working on is contingent upon checking a date in the data source against today’s date. Moment.js does not work in this context:

var date = moment().format(‘YYYY-MM-DD’);

This is what I am looking to do: `

//get today's date
var todaysDate = moment().format("DD-MM-YYYY");
//get subscription date from data source
var subscriptionEndDate = session.entries.dataSource.data['Subscription End Date'];
//compare date subscriptionDate greater than todaysDate
var subscriptionIsValid =  subscriptionEndDate > todaysDate;
if (server && page.id == mainMenu && subscriptionDateIsValid) {
  navigate = { action: 'screen', page: login, transition: 'slide.left' };
}

I am focused on getting the todaysDate, I can work out the rest, just putting it here for reference.

Thank you in advance.

Hi there,

Depending on the format you would like you can use one of these two lines:
var todaysDate = [new Date().getDate(), (new Date().getMonth() + 1), new Date().getFullYear()].join(‘-’) // DD-MM-YYYY
var todaysDate = [new Date().getFullYear(), (new Date().getMonth() + 1), new Date().getDate()].join(‘-’) // YYYY-MM-DD

1 Like