Created
November 7, 2022 23:11
-
-
Save sturmenta/71d8da5270479cd14c8503a989d268b4 to your computer and use it in GitHub Desktop.
validate user date greater than 13 years
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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