[thelist] [ColdFusion] udf question

.jeff jeff at members.evolt.org
Tue Nov 26 11:26:01 CST 2002


kyle,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Kyle Murphy
>
> Because CF5's IsDate(string) function lacks actually
> checking if the year is valid, I'm attempting to write
> a udf to check if it's between 1900-2500.  Here's what
> I have so far:
>
> var tempDate = date;
> if (IsDate(tempDate)) {
> var dateYear = DatePart(yyyy, tempDate);
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

the specific error you're getting is because of your use of the var keyword.
once you begin writing conditional logic, you can no longer use var.  you'll
need to do that first.  so, change it to something like this:

var tempDate = date;
var dateYear = '';
if(IsDate(tempDate))
{
  dateYear = Year(tempDate);

(i prefer to use the Year() function rather than the DatePart() function.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> var dateYear = DatePart(yyyy, tempDate);
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

the "yyyy" in the DatePart() function should be a string.  wrap that with
quotes (single or double, though i prefer single) and it should be fine.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> if (dateYear gte 1900 AND dateYear lte 2500) {
>   return "YES";
> }
> else {
>   return "NO";
> }
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

this could be shortened to one of the following (depends on how
adventuresome you are.

if(dateYear GTE 1900 AND dateYear LTE 2500)
  return 'YES';
else
  return 'No';

or even better:

return (dateYear GTE 1900 AND dateYear LTE 2500);

good luck,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/




More information about the thelist mailing list