As promised, a bonus for those who supported my sessions at Power Platform Conference, Las Vegas. You are awesome, thanks so much!
Again, please don’t share these with anyone else.
// create a moment object from the Date of Birth field var dateOfBirth = moment($('#jdr_dateofbirth').val()); // check whether dateOfBirth is before now var now = moment(); if(dateOfBirth.isBefore(now)) { true } else { false } // calcuate 'time ago' when a message was received (output as a string e.g. 2 weeks ago) var dateReceived = moment($('#jdr_datereceived').val()); var dateReceivedString = dateReceived.fromNow(); // calculate age from date of birth as number var calculatedAge = moment().diff(dateOfBirth, 'years'); console.log(calculatedAge); var dateFrom = moment($('#jdr_datefrom').val()); var dateTo = moment($('#jdr_dateto').val()); var periodWorked = dateFrom.diff(dateTo, 'years'); // Combining date diff with a duration in a given unit var calculatedAgeDecimal = moment.duration(moment().diff(dateOfBirth)) var maxDatePermitted = moment($('#jdr_dateFrom').val()).add(5, 'years'); // only allow to dates within 5 years of the dateFrom $('#jdr_dateto').next().data('DateTimePicker').maxDate(moment($('#jdr_datefrom').val()).add(5, 'years')); // only allow to dates within the next 5 years $('#jdr_dateto').next().data('DateTimePicker').maxDate(moment().add(5, 'years')); // only allow to dates later than form date $('#jdr_dateto').next().data('DateTimePicker').minDate(moment($('#jdr_datefrom').val()));