Validate the date field to be greater than x days from now.
Right now I have this snippet that checks if the date is greater than now.
planned_date: Joi.date().greater('now').required()
But I want to validate that the planned_date
is at least 2 days more than now.
This could be possible combining with moment.js
, but couldn't get it working.
const dateLater = moment.tz(new Date(), '').unix() + 48 * 60 * 60
This will give you date 2 days later at same time and then later on you can do thisplanned_date: Joi.date().greater(dateLater).required()
planned_date: Joi.date().required().greater(Date.now() + 48 * 60 * 60 * 1000)