Skip navigation
Currently Being Moderated

Calculate age in a function

Mar 16, 2010 6:00 AM

I am trying to calculate and return the age of a person. My code is:

    <cfset variable.age = '(dateDiff("yyyy",query.birthdate, now()))'>

I get a "If the expression is a string, ensure that it is within quotes. Error: report.ModStat(query.soc_sec)

is not a valid ColdFusion expression." error message when I try to run the report.

Any help would be appreciated.

Thanks.

 
Replies
  • Currently Being Moderated
    Mar 16, 2010 6:17 AM   in reply to Cozmo2

    The error you are quoting is not related to the line of code you quote, for starters.  So I think you're troubleshooting this froom the wrong place in your code.

     

    Secondly, this:

     

        <cfset variable.age = '(dateDiff("yyyy",query.birthdate, now()))'>

     

    Simply sets variable.age to the string  '(dateDiff("yyyy",query.birthdate, now()))'.  IE: exactly that string.  You should not have the outer single quotes (and the outer parentheses are unnecessary too).

     

    Should the statement be setting variable.age or variables.age?

     

    The first thing you should be doing when confronted with code that is breaking is to be inspecting the values of the contributing variables.

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 16, 2010 6:21 AM   in reply to Adam Cameron.

    In addition to the feedback above, many functions like that have been made and are posted at CFLib.org.

     

    http://www.cflib.org/udf/AgeSinceDOB

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points