Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
marco_puccetti
Partner - Creator
Partner - Creator

Date diff compute year

How can i do to make the year difference from 2 dates? I need it to compute the age.

Marco

1 Solution

Accepted Solutions
hic
Former Employee
Former Employee

There is an "Age" function that does exactly this:

     Age(timestamp, date_of_birth)

HIC

View solution in original post

14 Replies
Not applicable

You should be able to use FABS(Year(Date1)-Year(Date2))

FABS will give you the absolute value so it doesn't matter which way around the dates are.

Anonymous
Not applicable

year(date1)-year(date2)+1 (( +1 depending what result you expect for same year (0 or 1)

or not that what you want? then specify more your requirements

sujeetsingh
Master III
Master III

Interval function will help you out

Interval(Date1-Date2,'DD')

fvelascog72
Partner - Specialist
Partner - Specialist

Hi,

Try this:

DATA:

LOAD

  *,

  if(month(DeadDate)<month(BornDate),year(DeadDate)-year(BornDate)-1,year(DeadDate)-year(BornDate)) as "Age"

Inline [

BornDate, DeadDate

01/10/1950, 02/05/2015

01/01/1960, 03/08/2015

];

hic
Former Employee
Former Employee

There is an "Age" function that does exactly this:

     Age(timestamp, date_of_birth)

HIC

marco_puccetti
Partner - Creator
Partner - Creator
Author

Ok with year we can approximate the age from now.

Thanks

Marco

jonathandienst
Partner - Champion III
Partner - Champion III

If you need a more accurate age:

    Floor((Date1 - Date2) / 365.25)

     or

    Ceil((Date1 - Date2) / 365.25)

     or

    Round((Date1 - Date2) / 365.25, 0.1)

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
MK_QSL
MVP
MVP

Use this...

Reference

swuehl
buzzy996
Master II
Master II

use Interval() ,if u need u can specify format as well with the function.