Normal Topic Programming birthday and age for grade level (Read 1423 times)
BobBrandt
Member
*
Offline


No personal text

Posts: 6
Joined: Dec 16th, 2003
Programming birthday and age for grade level
Aug 24th, 2018 at 4:53pm
Print Post Print Post  
I have a database that has the birth date and age and I want to program the grade level the child is in. The grade level is determined by whether the child's birthday is before August 2nd or after August 1st. I am not familiar with all of the ways of determining dates in Sbasic but I have done these lines from Pre-K thru 12 to determine what grade. But, it is inaccurate when the new school year starts. The .dsr file is attached.

if @add and Age = 7 and Birthday <08/02/2011 then Grade = "2";
if @add and Age = 7 and Birthday >08/01/2011 then Grade = "1";

Can someone help me to determine the correct grade level when the new school year starts?
Thank you very much.
Bob Brandt
bjcbrandt@gmail.com
  

Children.dsr ( 87 KB | 88 Downloads )
Back to top
 
IP Logged
 
Wilder
Member
*
Offline



Posts: 25
Joined: Jun 11th, 2015
Re: Programming birthday and age for grade level
Reply #1 - Aug 31st, 2018 at 10:04pm
Print Post Print Post  
dsr not opening without ddt file
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Programming birthday and age for grade level
Reply #2 - Sep 11th, 2018 at 6:15pm
Print Post Print Post  
Hello,

If you are referring to the issue with the hardcoded year, 2011 in your example, you can fix that by changing those two lines to the lines directly below.
Code
Select All
if @add and Age = 7 and Birthday < @ToDate("08/02/" + (@Year(@Date) - 7)) then Grade = "2";
if @add and Age = 7 and Birthday > @ToDate("08/01/" + (@Year(@Date) - 7)) then Grade = "1";
 



Also rather than having 2 lines for each grade you can write one routine that handles any age and any birthday.

Code
Select All
Var vGrade as Int

If @Add Then
{
	//Calculate initial Grade
	vGrade = Age - 5
	If @ToDate(@Month(Birthday) + "/" + @DOM(Birthday) + "/" + @Year(@Date)) > @ToDate("08/01/" + @Year(@Date)) Then
	{
		//If their Birthday this year is greater than August 1st of this year, bump them down a Grade
		vGrade = vGrade - 1
	}

	If ((vGrade < 0) or (vGrade > 12)) Then
	{
		Clear(Grade)
	}
	Else If vGrade = 0 Then
	{
		Grade = "K"
	}
	Else
	{
		Grade = vGrade
	}
} 



-Ray
  

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