# Thread: Need help with Date conversions

1. ## Need help with Date conversions

Hi, I am a new user to this software and I have put together a database for data collection. I work for a fire department and I am in charge of collecting all the information on our calls.

I have a medical database and I would like to know how I can subtact a persons date of birth which is a field on its own from the incident date which I enter manually. I need this to display in just years. I would like to be able to just enter the patients date of birth in one field and the next field on my database is age. I would like this program to just auto enter the age from date of birth minus the incident date. I dont know where to begin to do this, so please help

Thanks very much

Dennis

2. ## Re: Need help with Date conversions

All depends on what you really mean by subtracting one date from another. If you want to calculate a number of years based on specific dates in two spearate years.

Code:
```d1 = {12/15/1975}
d2 = {04/22/1999}
? d2 - d1
= 8529.000000

? (d2 - d1)/365
= 23.367123```
If you want to know the difference in the year numbers.

Code:
```? year(d1)
= 1975.000000

? year(d2)
= 1999.000000

? year(d2)-year(d1)
= 24.000000```
If you want to know the age of a person given a specific date.

Code:
```d1 = {12/15/1975}
d2 = {04/22/1999}

? age(d1,d2)
= 23.000000```
Any of these calculations (d2 - d1)/365, year(d2)-year(d1), age(d1,d2) could be used as the defined expression for a calculated field in a table.

3. ## Re: Need help with Date conversions

Dennis,

From the Interactive Window...

?age({02/14/62},{10/02/06})
= 44

Hope this helps!

Louis

4. ## Re: Need help with Date conversions

Based on the above posts, I'm using the following to obtain the correct AGE from the person's DOB, based on the Date Reported:

AGE(DOB,DATEREP)

It works fine, except when there is no DOB. In those cases it is displaying the a negative number, which of course is correct.

Is there any way I can prevent it from displaying a number if the answer is zero or in the negatives?

5. ## Re: Need help with Date conversions

Rich,

Try a logic expression like:
if(AGE(DOB,DATEREP)<=0,"",AGE(DOB,DATEREP))

Dave

6. ## Re: Need help with Date conversions

Thanks for the reply Dave, but I'm getting a message that the equation does not result in a numeric value.

7. ## Re: Need help with Date conversions

Originally Posted by davej
Rich,

Try a logic expression like:
if(AGE(DOB,DATEREP)<=0,"",AGE(DOB,DATEREP))

Dave
Since age returns a number I don't think that would work. You could use

if(AGE(DOB,DATEREP)<=0,0,AGE(DOB,DATEREP))

and set the field format to "1234567.78 (blank if zero)" in the object properties or

if(AGE(DOB,DATEREP)<=0,"",alltrim(str(AGE(DOB,DATEREP))))

8. ## Re: Need help with Date conversions

Works like a champ!

Thanks Stan and Dave for the assistance.

#### Posting Permissions

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