Computing age from a date

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Computing age from a date

    Hello Everyone,

    I understand how to compute the age from the date of birth on a single record.


    <cfset pat_age=#datediff('yyyy',DateOfBirth,TreatmentDate )#>

    I have a table which holds of which has a date of precedure and other fields.
    I have another table which will give the Date Of Birth. How can I determine
    the age of a person at a date and then insert into the List I need to output.

    <cfquery datasource="#ds#" name="getprocedurelist">
    SELECT *
    FROM tbltreatmentlist
    WHERE TreatmentListclientID=#session.clientID#
    </cfquery>

    <cfquery datasource="#DS#" name="getPatientDOB">
    SELECT PATBirthDate
    From tblPatientInformation
    </cfquery>

    <cfquery datasource="#DS#" name="getClientDOB">
    SELECT BirthDate
    From tblClientInformation
    </cfquery>

    <cfif getpatientDOB.recordCount IS 0>
    <cfset DateOfBirth=#GetPatientDOB.patBirthdate#>
    <cfelse>
    <cfset DateOfBirth=#GetclientDOB.Birthdate#>
    </cfif>

    and the output;

    <tr>
    <th>age</th>
    <tH>date</tH>
    <th>doctor</th>
    <th>Procedure type/description</th>
    <th>Marked?</th>
    </tr>
    <tr>
    <td><!---get the age at treatment---></td>
    <td><cfif session.usertype IS 1><input type="text" name="ProcedureDate"
    <cfif action IS "change">
    value="#dateformat(ProcedureDate,"mm/dd/yyyy")#"</cfif>><cfelse>#dateformat(Proc
    edureDate,"mm/dd/yyyy")#|</cfif></td>
    <td><input type="text" name="Doctor" <cfif action IS
    "change">value="#doctor#"</cfif>></td>
    <td><input type="text" name="Description" <cfif action IS "change">
    value="#Description#"</cfif>></td>
    <td><input type="text" name="Marked" <cfif action IS
    "change">value="#Marked#"</cfif>></td>
    </tr>
    </cfoutput>
    <cfelse>
    <tr>
    <td colspan="5">There are no procedures entered yet.</td>
    </tr>

    </cfif>

    As you can clearly see....I am lost..

    Thanks for your help

    shastamatt Guest

  2. Similar Questions and Discussions

    1. Computing columns in dtagrids
      Hi all :-) I'm having a BIG problem with getting a grand total in a data grid. I'm sorry, this is sort-of a double-post, but I REALLY need some...
    2. University of Plymouth Computing Industry Perception Study
      First of all, can I reassure you that this posting is NOT spam and not market research. Please feel free to email me at the address below to...
    3. Univeristy of Plymouth Computing Industry Perception Study
      First of all, can I reassure you that this posting is NOT spam and not market research. Please feel free to email me at the address below to...
    4. [PHP] computing 2 value and adding it..
      if($pcs_1000){ $total = $amount * 2; } -----Original Message----- From: Louie Miranda Sent: Sunday, July 20, 2003 7:53 PM To:...
    5. [SUN] Throughput Computing
      Paul Gress <pgress@pb.net> writes: Have you tried the port of Pro/ENGINEER Wildfire to GNU/Linux? HP sells GNU/Linux workstations that are...
  3. #2

    Default Re: Computing age from a date

    I'm assuming you're looping throught the 'getprocedurelist' query to output the
    information. So, you just calculate the age at each iteration of your query
    output loop.

    ================================================== =========
    <cfquery datasource="#ds#" name="getprocedurelist">
    SELECT *
    FROM tbltreatmentlist
    WHERE TreatmentListclientID=#session.clientID#
    </cfquery>

    <cfquery datasource="#DS#" name="getPatientDOB">
    SELECT PATBirthDate
    From tblPatientInformation
    </cfquery>

    <cfquery datasource="#DS#" name="getClientDOB">
    SELECT BirthDate
    From tblClientInformation
    </cfquery>

    <cfif getpatientDOB.recordCount IS 0>
    <cfset DateOfBirth=#GetPatientDOB.patBirthdate#>
    <cfelse>
    <cfset DateOfBirth=#GetclientDOB.Birthdate#>
    </cfif>

    <!--- Output ages at time of treatment --->
    <cfoutput query="getprocedurelist">
    <cfset pat_age = DateDiff('yyyy', variables.DateOfBirth,
    getProcgetprocedurelistedureList.TreatmentDate)>
    My age at the time of treatment was: #pat_age#<br />
    </cfoutput>
    ================================================== =========

    Either that or you could just use the 'datediff' function in your
    'getprocedurelist' SQL statement so it's returning it as a query column.
    Personally, I'd opt for the latter.

    BSterner Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139