Skip to content

Instantly share code, notes, and snippets.

@sturmenta
Created November 7, 2022 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturmenta/71d8da5270479cd14c8503a989d268b4 to your computer and use it in GitHub Desktop.
Save sturmenta/71d8da5270479cd14c8503a989d268b4 to your computer and use it in GitHub Desktop.
validate user date greater than 13 years
import dayjs from 'dayjs';
export const validateAtLeast13Years = (DDMMYYYY?: string): boolean => {
if (!DDMMYYYY) return false;
const timePickerDate = DDMMYYYY.split('/').reverse().join('-');
const date1 = dayjs();
const date2 = dayjs(timePickerDate);
const diff = date1.diff(date2, 'years');
return diff >= 13;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment