Last active
May 11, 2020 11:03
-
-
Save dwhiteGUK/ad7fe6e8b2e42742a3b099dfdbb9dacf to your computer and use it in GitHub Desktop.
Working with JS Date and Date-fns library
This file contains hidden or 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
| // Max Date | |
| const { format, isBefore, isValid, subYears, parseISO } = require('date-fns'); | |
| const maxDate = format(subYears(new Date(), 18), 'yyyy-MM-dd'); | |
| const maxResult = isBefore(dobDate, parseISO(maxDate, 1)); | |
| // Min Date | |
| // Requires Date FNS | |
| const { format, isAfter, subYears, parseISO } = require('date-fns'); | |
| const minDate = format(subYears(new Date(), 150), 'yyyy-MM-dd'); | |
| const maxResult = isAfter(dobDate, parseISO(maxDate, 1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment