API v2.1.x

Installation:

npm: npm install @joi/date

yarn: yarn add @joi/date

Compatibility

This version requires joi v17 or newer.

Rules

date.format(format)

Specifies the allowed date format:

  • format - string or array of strings that follow the moment.js format.
const schema = Joi.date().format(['YYYY/MM/DD', 'DD-MM-YYYY']);
const schema = Joi.date().format('YYYY-MM-DD HH:mm');

date.utc()

Dates will be parsed as UTC instead of using the machine's local timezone.

const schema = Joi.date().utc().format(['YYYY/MM/DD', 'DD-MM-YYYY']);