Normal Topic Using a fixed date (Read 151 times)
DylanFan
Member
*
Offline



Posts: 4
Joined: Apr 2nd, 2024
Using a fixed date
Mar 25th, 2025 at 10:22am
Print Post Print Post  
I’m trying to calculate someone’s age from their birthday to another date (not today’s date).
I’ve got a date element “performed” and one for the age.
I’ve tried “age = performed - @D(yyyy/mm/dd)” & also did/mm/yyyy with no joy. I’ve also added “/ 365.25” at the end but again no joy.
I’m not a programmer, have come from Q&A, and have very limited knowledge.
Maurice
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2492
Joined: Aug 20th, 2003
Re: Using a fixed date
Reply #1 - Mar 25th, 2025 at 1:29pm
Print Post Print Post  
Hi Maurice,

To accurately calculate their age, your code will have to be a bit more complex than that. An example is below. Now you did not say which element held their birthday, as that is the first value the is needing to be passed to the function and the second argument is the date you wanna calculate their age at(which I am assuming is Performed?)

Code
Select All
Function CalcAge(vDOB as Date, vDate as Date) as Int
Var vAge as Int

	vAge = @YEAR(vDate)-@YEAR(vDOB) - ((@MONTH(vDate) < @MONTH(vDOB)) or (@MONTH(vDate) = @MONTH(vDOB) AND @DOM(vDate) < @DOM(vDOB)))

	Return(vAge)
End Function

Age = CalcAge(Birthday, Performed) 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
DylanFan
Member
*
Offline



Posts: 4
Joined: Apr 2nd, 2024
Re: Using a fixed date
Reply #2 - Mar 25th, 2025 at 2:26pm
Print Post Print Post  
Hi Ray, thanks for the response.

I did not have an element for the birthday, just assumed I could include that in the programming.
I had tried to do it that way but it also failed.
I added a birthday element (date format) that is auto loaded with the date but I don’t know what format to use dd/mm/yyyy, yyyy/mm/dd etc as I know this has to be correct.
Maurice
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2492
Joined: Aug 20th, 2003
Re: Using a fixed date
Reply #3 - Mar 25th, 2025 at 2:34pm
Print Post Print Post  
Hi Maurice,

As long as it is a Date element, the display format does not matter as it doesn't affect how the data is stored just how it is displayed.

You can include it in the programming. You would just use @ToDate("1965/03/21") in place of Birthday for a birthday of March 21st 1965. Specifying it as YYYY/MM/DD helps prevent ambiguity in the input date.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
DylanFan
Member
*
Offline



Posts: 4
Joined: Apr 2nd, 2024
Re: Using a fixed date
Reply #4 - Mar 25th, 2025 at 3:05pm
Print Post Print Post  
Thanks Ray, I’ll have a play about with it later.
Maurice
  
Back to top
 
IP Logged
 
DylanFan
Member
*
Offline



Posts: 4
Joined: Apr 2nd, 2024
Re: Using a fixed date
Reply #5 - Mar 26th, 2025 at 8:20am
Print Post Print Post  
Thanks Ray, all working okay now.
  
Back to top
 
IP Logged