What `type` do people use to validate dates for SQ...
# box-products
s
What
type
do people use to validate dates for SQL datetimes? values like
20200101
pass the
isValid( "date")
check, and I know there's
usdate
but the lucee docs say not to use that
z
Use a mask whenever possible
s
that'd be a udf validator in cbvalidation, no? I was wondering if there was any shorthand for it
z
s
I know how to do a real date check. I was just wondering if cbvalidation has any of them built in so I can just slap it in the constraints without having to write a udf validator or a custom validator every time
and if it isn't built in, whether one should be added
z
But if it parses to a date, it's valid, otherwise it throws doesn't it?
s
20200101
parses to a date but then fails as a SQL param because CF sends
{ts '20200101-01-01 00:00:00'},
CF being notoriously lax about what it considers date-able
✔️ 1
not unlike my college roommate
s

https://c.tenor.com/Oo6exgunJ0IAAAAC/oh-snap-burn.gif

it appears the only check begin done is
Copy code
case "date": {
				r = isValid( "date", arguments.targetValue );
				break;
			}
i would say you have to either use a regex match, or add a new method like
dateMatchesFormat(date,'mm-dd-yyyy')
w
The date checks in cbvalidation are quite limited but that's because it is a simple wrapper to isvalid which is not always useful especially for i18n. But you only have to write this custom validator once Sam, and use it all the time. Or use the regex validator which is already there
Custom validator are almost trivial to write. Most of it is template code
s
Yeah we use them, but if I was going to write one, I'd probably put in a PR. isValid is useless for dates
w
I think it would be difficult to write a generic datevalidator, unless you use a mask param so you can at least tell the validator what kind of input to expect. I really hate isvalid for dates
Isvalid also breaks qb param detection, because it thinks some stupid strings are dates
r
@sknowlton @wil-shiftinsert if you have written a custom date validator I would be interested in the code as I need one myself.
w
I have written multiple custom date validators. There are too many options to create one for all needs. Sometimes people are entering dd mm and yy in separate fields, sometimes in one single field. Separators and order differ per country. It is quite easy to write one. Just let me know what you need and I'll give it a try next week and make the code available.
s
I feel like a generic would have to include an array of allowable masks like Wil said
w
I think I will try that approach. But now still enjoying my vacation in the French Alps 🏔️🏔️🍷🥖
s
vacation in the french alps is the opposite of coldfusion date validators
🤣 1
w
Definitely 😀 but so relaxed here I even don't know if date formats are the same as at home. Language is different though, and so is the food. And we have no mountains 😢
s
message has been deleted