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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

to calculate AGE fromDOB

Status
Not open for further replies.

PeriyurParthi

IS-IT--Management
Jul 18, 2001
258
IN
is there any function or sql query to calculate age of an employee from given data of birth.. pls let me know
cheers
parthi
 
Hi Parthi,
I also have to calculate the date difference for so many reasons. So you can create a function like following:

*--Function- DateDiff(date,date) returns String--*
LPARA dob, today
IF PARA()<>2
RETURN 'Invalid Range'
ENDIF
setdate=SET('DATE')
setcent=SET('CENTURY')
SET DATE BRITISH
SET CENT ON
yr=YEAR(today)-YEAR(dob)
IF MONTH(today)>=MONTH(dob)
mt=MONTH(today)-MONTH(dob)
ELSE
yr=yr-1
mt=12-(MONTH(dob)-MONTH(today))
ENDIF

IF DAY(today)>=DAY(dob)
dy=DAY(today)-DAY(dob)+1
ELSE
dy=DAY(CTOD('1/'+ALLT(STR(MONTH(today)))+'/'+ALLT(STR(YEAR(today))))-1)-(DAY(dob)-DAY(today))
ENDIF
SET DATE &setdate
set cent &setcent
Return ALLT(STR(yr))+' Year(s) '+ALLT(STR(mt))+' Month(s) '+ALLT(STR(dy))+' Day(s)'


And then call this function as datediff(dob,date()) anywhere you require.

Hope it helps!!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top