在 OpenOffice 中計算年齡(以天/月/年為單位)

在 OpenOffice 中計算年齡(以天/月/年為單位)

需要在 OpenOffice 中尋找以天、月、年為單位的年齡。

DATEDIF()Microsoft Excel 中有。您可以使用它來找出兩個日期之間的天/月/年差異。

Age Calculation 
    You can calculate a persons age based on their birthday and todays date.
    The calculation uses the DATEDIF() function.        
    The DATEDIF() is not documented in Excel 5, 7 or 97, but it is in 2000. 
    (Makes you wonder what else Microsoft forgot to tell us!)   
    Birth date :    01-Jan-60       
    Years lived :   52   =DATEDIF(C8,TODAY(),"y")   
    and the months :    4    =DATEDIF(C8,TODAY(),"ym")
    and the days :  30   =DATEDIF(C8,TODAY(),"md")

可以透過下面的公式計算,但是計算月份比較麻煩。

Another way to calculate age         
This method gives you an age which may potentially have decimal places representing the months.
If the age is 20.5, the .5 represents 6 months.             
Birth date :    01-Jan-60
Age is :    52.41    =(TODAY()-C23)/365.25

答案1

只需使用YEARS()MONTHS()函數來自集合日期/時間函數:

=YEARS(01-Jan-60,NOW,1)

=MONTHS(01-Jan-60,NOW,1)

將為您提供過去的年數和月數的總和。要從年份總和中取得剩餘月份,只需使用模(在 Calc 中:MOD()):

=MOD(MONTHS(01-Jan-60,NOW,1), 12)

將返回月份總和除以 12 後剩餘的 4 個月。

當然,您可以用單元格引用替換上面公式中包含的日期。=YEARS(A1,A2,1)假設儲存格 A1 和 A2 包含日期。

相關內容