Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert date to month counter

Status
Not open for further replies.

JMB7

MIS
May 19, 2004
26
US
Crystal 8.5
SQL Database

Good Morning,
I am trying to calculate patient age by months. I have a patient date of birth field and am subtracting that date from a vst start date field to get current age.
@Age=Month({vst.vst_start_date}) - Month({pt.birth_dtime})

When the report runs, I just get the calculation between the months regardless of the year. This does not work when the vst start date and the birthdate fields are different years. Any help would be appreciated. Thank you
Example:
REG DATE PT AGE IN MONTHS DOB
Patient A 07/13/2005 -5.00 12/03/2002
Patient B 02/14/2005 -10.00 12/09/2002
Patient C 07/22/2005 -5.00 12/22/2002

Looking For:
REG DATE PT AGE IN MONTHS DOB
Patient A 07/13/2005 32.00 12/03/2002
Patient B 02/14/2005 27.00 12/09/2002
Patient C 07/22/2005 32.00 12/22/2002

 
Try datediff("m",{pt.birth_dtime},{vst.vst_start_date})


-lw
 
For the age in months, try
Code:
DateDiff("m", ({pt.birth_dtime}, {vst.vst_start_date})

For age in years, you'd use the same formula but "yyyy". Or if you wanted a more accurate figure, use "d", days, and then divide the result by 30.




[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
It works! Thank you both very much
Madawc - thanks for the extra hints.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top