Age
Most tools do not have a specific age function so you need to use a version of a Date difference
calculation. For more information on these, go to Dates > Date Difference.
Excel
Excel does not have a specific Age function so use =DATEDIF()
and supply today's date as the end date.
=~DATEDIF!~(‹start_date›, ~TODAY()!~, "‹date_part›")
=DATEDIF(A1, TODAY(), "D")
NB. Supported date parts are as follows (all fractions are rounded down):
Date Part
Equates to
Min : Max Values
"D"
Days
-∞ : ∞
"M"
Months
-∞ : ∞
"Y"
Years
-∞ : ∞
"MD"
Days (irrespective of month & year of the two dates)
0 : 30
"YD"
Days (irrespective of the year of the two dates)
0 : 364
"YM"
Months (irrespective of the year of the two dates)
0 : 11
Tableau
Tableau does not have a specific Age function so use DATEDIFF()
and supply today's date as the end date.
~DATEDIFF!~('‹datepart›', ‹start_date›, ~TODAY()!~«, start_of_week»)
DATEDIFF('year', [Date of Birth], TODAY())
NB.
«start_if_week» is used to determine rounding of weeks. If omitted, it is determined by Tableau automatically from the data source.
Supported date parts are as follows (all fractions are rounded up):
Date Part
Equates to
'year'
Years
'quarter'
Quarters
'month'
Months
'week'
Weeks
'day'
Days
'hour'
Hours
'minute'
Minutes
'second'
Seconds
Alteryx
Alteryx does not have a specific Age function so use DATETIMEDIFF()
and supply today's date as the end date.
~DATETIMEDIFF!~(‹start_date›, ~DATETIMETODAY()!~, ‹date_part›)
DATETIMEDIFF([Date of Birth], DATETIMETODAY(), 'year')
NB. Supported date parts are as follows (all fractions are rounded down):
Date Part
Equates to
'year' / 'years'
Years
'month' / 'months'
Months
'day' / 'days'
Days
'hour' / 'hours'
Hours
'minute' / 'minutes'
Minutes
'second' / 'seconds'
Seconds
OrgVue
node.‹date›.~age!~('«date_part»')
node.dateofbirth.age('y')
NB. Supported date parts are as follows (fractions are not rounded):
Date Part
Equates to
'y'
Years
'q'
Quarters
'm'
Months
'w'
Weeks
'd'
Days
tSQL
tSQL does not have a specific Age function so use DATEDIFF()
and supply today's date as the end date.
~DATEDIFF!~(‹date_part›, ‹start_date›, ~GETDATE()!~)
SELECT DATEDIFF(year, DateOfBirth, GETDATE()) AS Age
FROM EmployeesData
NB. Supported date parts are as follows (fractions are not rounded):
Date Part
Equates to
year
Years
quarter
Quarters
month
Months
day
Days
week
Weeks
hour
Hours
minute
Minutes
second
Seconds
microsecond
Mircroseconds
nanosecond
Nanoseconds
Python
Python does not have a specific Age function so use: ~datetime.date!~(‹end_date›) - ~datetime.date.!~(‹start_date›)
from datetime import date
# so you don't have to reference datetime.date() to call each date
date(finishDate) - date.(transferDate)
# OR
date(2016,10,18) - date(2015,11,23)
This returns a date object. To unpack it as a number of days, wrap the difference expression in ()
and append .days
:
from datetime import date
(date(2016,10,18) - date(2015,11,23)).days
NB.
This requires the
datetime
library to be imported.This returns the difference in days which can be divided/multiplied to give other units.
When manually creating a date, days and months must be entered as a single digit when < 9 (with no padding '0'), e.g.
date(2016,9,20)
.The example above assumes variables have been declared for
finishDate
andtransferDate
. For more information, go to General > Variables.
Last updated
Was this helpful?