When utilizing 'DD-MM-YYYY'
with momentjs, it results in an invalid date format.
const selectedValue = moment('30-08-2022').format('DD-MM-YYYY');
console.log(selectedValue)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
To ensure it is a valid date, include 'DD-MM-YYYY'
in the second parameter of the moment
function after the date and format it.
const selectedValue = moment('30-08-2022','DD-MM-YYYY').format('DD-MM-YYYY');
console.log(selectedValue)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
If you must use 'DD-MM-YYYY'
in your code without encountering a deprecation warning, you can do the following
const selectedValue = moment('30-08-2022', 'DD-MM-YYYY').format('DD-MM-YYYY');
console.log(selectedValue)
const today = moment().format('DD-MM-YYYY');
console.log(today)
const yearDiff = moment(today, 'DD-MM-YYYY').diff(moment(selectedValue, 'DD-MM-YYYY'), 'years');
console.log(yearDiff);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>