I have to check on a specific date the age in months.
I have this code
GLOBAL CODE // Returns a date that is vMonths from vStartDate // Use negative vMonths to get a date before vStartDate FUNCTION GetDateByMonths(vStartDate as Date, vMonths as Int) as Date var vRet as Date var vYear as Int var vDay as Int var vMonth as Int var vOffset as Int var vDir as Int // Add (1) or subtract (-1) months
vRet = vStartDate vDir = 1 vOffset = vMonths
// Split date into pieces vYear = @Int(@Year(vStartDate)) vDay = @DOM(vStartDate) vMonth = @Month(vStartDate)
// Work with a positive number of months If vOffset < 0 { vDir = -1 vOffset = @Abs(vOffset) }
// Adjust months If vDir = 1 { vMonth = vMonth + vOffset
// Adjust for multiple years While vMonth > 12 { vYear = vYear + 1 vMonth = vMonth - 12 } } Else { vMonth = vMonth - vOffset
// Adjust for multiple years While vMonth < 1 { vYear = vYear - 1 vMonth = vMonth + 12 } }
// Assemble new date vRet = @Str(vYear) + "/" + @Text(2 - @Len(@Str(vMonth)), "0") + @Str(vMonth) + "/" + @Text(2 - @Len(@Str(vDay)), "0") + @Str(vDay) Return vRet
END FUNCTION
and
Element Leeftijd0 On element entry
var vBirthdate as Date var vFirst as Date var vLast as Date
if klasse = 1 then { vBirthdate = GEB_D vFirst = GetDateByMonths(datum_keuring, -6) // Get date 6 months before Datum keuring vLast = GetDateByMonths(datum_keuring, -9) // Get date 9 months before Datum keuring If (vBirthdate >= vFirst) And (vBirthdate <= vLast) { @MSG("Good Dog!") } Else { WriteLn("Bad Dog!") } }
else if klasse = 2 then { vBirthdate = GEB_D vFirst = GetDateByMonths(datum_keuring, -15) // Get date 15 months before Datum keuring vLast = GetDateByMonths(datum_keuring, -9999) // Get date 9999 months before Datum keuring If (vBirthdate >= vFirst) And (vBirthdate <= vLast) { @MSG("Good Dog!") } Else { WriteLn("Bad Dog!") } }
else if klasse = 3 then { vBirthdate = GEB_D vFirst = GetDateByMonths(datum_keuring, -18) // Get date 18 months before Datum keuring vLast = GetDateByMonths(datum_keuring, -24) // Get date 24 months before Datum keuring If (vBirthdate >= vFirst) And (vBirthdate <= vLast) { @MSG("Good Dog!") } Else { WriteLn("Bad Dog!") } }
else if klasse = 4 then { vBirthdate = GEB_D vFirst = GetDateByMonths(datum_keuring, -9) // Get date 9 months before Datum keuring vLast = GetDateByMonths(datum_keuring, -18) // Get date 18 months before Datum keuring If (vBirthdate >= vFirst) And (vBirthdate <= vLast) { @MSG("Good Dog!") } Else { WriteLn("Bad Dog!") } }
else if klasse = 5 then { vBirthdate = GEB_D vFirst = GetDateByMonths(datum_keuring, -15) // Get date 15 months before Datum keuring vLast = GetDateByMonths(datum_keuring, -9999) // Get date 9999 months before Datum keuring If (vBirthdate >= vFirst) And (vBirthdate <= vLast) { @MSG("Good Dog!") } Else { WriteLn("Bad Dog!") } }
else if klasse = 6 then { vBirthdate = GEB_D vFirst = GetDateByMonths(datum_keuring, -15) // Get date 15 months before Datum keuring vLast = GetDateByMonths(datum_keuring, -9999) // Get date 9999 months before Datum keuring If (vBirthdate >= vFirst) And (vBirthdate <= vLast) { @MSG("Good Dog!") } Else { WriteLn("Bad Dog!") } }
else if klasse = 7 then { vBirthdate = GEB_D vFirst = GetDateByMonths(datum_keuring, -144) // Get date six months before Datum keuring vLast = GetDateByMonths(datum_keuring, -9999) // Get date nine months before Datum keuring If (vBirthdate >= vFirst) And (vBirthdate <= vLast) { @MSG("Good Dog!") } Else { WriteLn("Bad Dog!") } }
Leeftijd0 = GetDateByMonths(Datum_keuring, 0) // Get date 0 months before Datum keuring
goto ring[/tr]
What everi try i always get the message "Bad Dog"
What i have do wrong in de code?
W
|