Age in Year Month Day Format

Copied from QV Community.

SET DateFormat=’DD/MM/YYYY’;

INPUT:

LOAD *

, if(day(VisitDay) >= day(DoB),

  mod(MonthIDVisitDay-MonthIDDoB,12),

  mod(MonthIDVisitDay-MonthIDDoB,12)-1) as AgeMonths

, if(day(VisitDay) >= day(DoB),

  day(VisitDay)-day(DoB),

  VisitDay-addmonths(DoB,12*AgeYears+mod(MonthIDVisitDay-MonthIDDoB,12)-1))+1 as AgeDays

;

LOAD *

, age(VisitDay,DoB) as AgeYears

, Year(DoB)*12+Month(DoB) as MonthIDDoB

, Year(VisitDay)*12+Month(VisitDay) as MonthIDVisitDay

INLINE [

DoB, VisitDay

01/01/2011, 11/03/2012

01/01/2010, 29/02/2012

01/03/2010, 29/02/2012

];

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.