Purpose
Returns the calculated age in the specified unit from the given arguments. You can call this function from the MapBasic window in MapInfo Pro.
Syntax
Age ( param1, param2, unit )
param1 (Date/Time/DateTime): First Input argument.
param2 (Date/Time/DateTime): Second Input argument. Should be same type as param1.
unit (String) - Date/Time/DateTime units: Should be based on the type of param1.
Date Units - day, week, month, year, century, decade.
Time Units - hr, min, sec.
Return Value
Float
Description
Returns the calculated age in the specified unit from the given two arguments. This function accepts two date, datetime, or time type arguments and a corresponding unit.
If any one of the parameters is null, 0 is returned.
Note: Similar to difference between param1 and param2
converted into specified units.
Example
Update RiotsLondonMapped Set Duration = Age(Committed_to_Date, Committed_on_from_Date, "day")
DropIndex Auto
dim dt1 as DateTime
dim dt2 as DateTime
dt1 = NumberToDateTime(20110807000100000)
dt2 = NumberToDateTime(20110905230000000)
print Age (dt2, dt1, "day") 'returns 29.567
print Age (dt2, dt1, "year") 'returns 0.0832157
print Age (dt2, dt1, "month") 'returns 0.998588
print Age (dt2, dt1, "hr") 'returns 718.983
print Age (dt2, dt1, "sec") 'returns 2588340
print Age (dt2, dt1, "min") 'returns 43139