I have an CV and would like to automatically update my age when opening. So, what formula should I insert in a MS Word field?
Something like:
{= {DATE} - {"01/01/1983"} }
I have an CV and would like to automatically update my age when opening. So, what formula should I insert in a MS Word field?
Something like:
{= {DATE} - {"01/01/1983"} }
This is one of the better sites for working with Word field codes - http://www.addbalance.com/usersguide/fields.htm - and there are examples there on how to create +/- dates.
Here's how you would calculate based of a birth month of January and birth year of 1983.
{IF{DATE\@"MM"} >= 01 { = {DATE\@"YYYY"} – 1983 \#"00"} { = {DATE\@"YYYY"} – 1984 \#"00"}}
Note that in the case of the month of January, this IF statement will always be true and give you =YEAR-1983. You can use another nested IF statement to check on the day to further get more accurate.
I tried but could not find in Word fields the equivalent of the Excel way to substract a daytime from another one (let’s say 05/18/1983 from today 03/21/2013) which is easy in Excel since a daytime (01/01/1900 in Excel 2013) has been chosen as the beginning and every other day since is calculated according to this reference, the shown details only being a way of representing this result (full date, month in figures or its full name, or even the simple number of Excel), which can be toggled by right clicking on the cell and choosing the category cell format (since 01/01/1900 is 1, then 05/18/1983 is 30454 (...and also 00/01/1900 is 0!)).
To answer the initial question, I suggest this writing:
{= {DATE \@ "YYYY"} - my_year - 1*{=OR({={DATE \@ "MM"} < my_month};{=AND({={DATE \@ "MM"} = my_month};{={ DATE \@ "dd"} < my_day})})} \* MERGEFORMAT}
bearing in mind:
The MERGEFORMAT option is useful to keep the correct format.
Also, for those who are not used to working with Word fields:
That would do for 05/18/1983 (I changed 1st of January, which is 01/01 to 18th of avoid confusion):
{= {DATE \@ "YYYY"} - 1983 - 1*{=OR({={DATE \@ "MM"} < 05};{=AND({={DATE \@ "MM"} = 05};{={ DATE \@ "dd"} < 18})})} \* MERGEFORMAT}
I would suggest calculating a serial number for both dates and subtracting them from each other. It doesn't have to be too involved: we're only interested in the number of years anyway. year*365 + month*31 + day should do nicely here.
For the number of years divide the difference by 365. Then strip the fractional part using INT (not ROUND which would make you 1 year older half of the year).
{ = INT(({ DATE \@"YYYY" }*365 + { DATE \@"MM" }*31 + { DATE \@"dd" }
- (my_year*365 + my_month*31 + my_day)) / 365) \# "0" }
{={DATE \@ "yyyy"} — {BirthDate \@ "yyyy"}}
I've done something like this:
10.2014 – 05.2020 (date1 - date2)
5 years, 8 months (difference)
I've mapped "10.2014" as bookmark (insert > bookmark) with the name "d1" (it will come in handy later. "05.2020" is the "Date" (insert > field > Date) formatted as {DATE \@ "MM.yyyy"}
. To access this, RMB > Toggle Field Codes
The next step is compute the "5 years, 8 months" difference. For this, I've computed separately the "years" and "months" numbers, with two different fields, as follows: field1 years, field2 months where
field1 = {= Round ((20*365+5*30 - 14*365-10*30)/365-0.4999,0}
field2 = {=(({Date \@""yy"}-{d1 \@"yy"}) - Round(({Date\@""yy"}*365 + {Date\@""M"}*30 - {d1 \@"yy"}*365 - {d1 \@"M"}*30)/365 -0.4999,0)*12 + ({Date \@ "M"} - {d1 \@ "M"}) + 1)
It can be further tweaked to show "year" or "years", "month" or "months" , but for me was enough.
Some further explanations:
{}
. Use Ctrl+F9 to insert a field© 2022 - 2024 — McMap. All rights reserved.
excel-formula
tagged question on SO. check out the link attached and you'll see :) – Bluejacket