在 MS Word 字段中显示日期差异

发布于 2024-08-30 02:52:48 字数 125 浏览 3 评论 0原文

我有一份简历,希望在开业时自动更新我的年龄。那么,我应该在 MS Word 字段中插入什么公式呢?

像这样的东西:

{= {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"} }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

孤蝉 2024-09-06 02:52:48

这是处理 Word 字段代码的最佳网站之一 - http://www.addbalance。 com/usersguide/fields.htm - 那里有关于如何创建 +/- 日期的示例。

以下是根据 1 月出生月份和 1983 年出生年份进行计算的方法。

{IF{DATE\@"MM"} >= 01 { = {DATE\@"YYYY"} – 1983 \#" 00"} { = {DATE\@"YYYY"} – 1984 \#"00"}}

请注意,在一月份的情况下,此 IF 语句将始终为 true 并为您提供 =YEAR- 1983年。您可以使用另一个嵌套 IF 语句来检查当天,以进一步获得更准确的结果。

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.

合约呢 2024-09-06 02:52:48

我尝试过,但在Word字段中找不到与Excel中从另一个时间减去白天的方法相同的方法(比方说从今天03/21/2013开始,从1983年5月18日开始),这在Excel中很容易从白天(01/01)开始Excel 2013 中的 /1900)已被选为开始,此后每隔一天根据此参考进行计算,显示的详细信息仅是表示此结果的一种方式(完整日期、数字中的月份或其全名,甚至是Excel 的简单数字),可以通过右键单击单元格并选择类别单元格格式来切换(因为 01/01/1900 是 1,那么 05/18/1983 是 30454(...还有 00/01/ 1900 是 0!))。

为了回答最初的问题,我建议这样写:

{= {DATE  \@ "YYYY"} - my_year - 1*{=OR({={DATE  \@ "MM"} < my_month};{=AND({={DATE  \@ "MM"} = my_month};{={ DATE  \@ "dd"} < my_day})})}  \* MERGEFORMAT}

请记住:

  1. 大括号 {} 是单词特定符号(不是普通的“字母”),应通过按 CTRL+F9 插入。
  2. 'my_year','my_month'(两次)和'my_day':应该是数字,
  3. 这篇文章很短,建议只进行4处更改(不幸的是月份两次),这将有助于防止
  4. 初学者犯错误,这篇文章说:今天的年减去 my_year,如果今天的月份值低于 my_month 或两者相等并且今天的值低于 my_day,则减一,这样我们就不会多加一年。

MERGEFORMAT 选项对于保持正确的格式很有用。

另外,对于那些不习惯使用 Word 字段的人:

  • 右键单击大括号 {} 内的文本并选择“切换字段代码”,从代码本身(内部文本)或此代码的演算结果切换,但这可能不是最新的(可能是以前的结果,代码也已更改)。
  • 要确保结果是最新的,请右键单击并选择“更新字段”。
  • 并确保打开主字段内的每个字段,选择整个字段(最好选择包含它的整行),右键单击并选择“切换字段代码”(否则,某些字段编码错误或可能返回void 表达式,可能看不到,并且可能会在不需要时影响以后的查看结果)。

这适用于 1983 年 5 月 18 日(我将 1 月 1 日更改为 1 月 1 日,以避免混淆):

{= {DATE  \@ "YYYY"} - 1983 - 1*{=OR({={DATE  \@ "MM"} < 05};{=AND({={DATE  \@ "MM"} = 05};{={ DATE  \@ "dd"} < 18})})}  \* MERGEFORMAT}

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:

  1. that curly brackets {} are Word specifics symbols (not normal ‘letters’) and should be inserted by pressing CTRL+F9.
  2. 'my_year', 'my_month' (twice) and 'my_day': should be numbers
  3. this writing is quite short, and suggest only 4 changes (unfortunaletly the month twice), which would help preventing errors
  4. for the beginners, this writing says: today's year minus my_year, and substract one if either today's month value is lower than my_month or both is equal and today's day value is lower than my_day, so that we do not have added one year in excess.

The MERGEFORMAT option is useful to keep the correct format.

Also, for those who are not used to working with Word fields:

  • right clicking on the text inside curly brackets {} and choosing “Toggle Field Codes”, switches from the code itself (texte inside) or the result of the calculus of this code, but that may not be up to date (may be a previous result also the code has been changed).
  • to make sure the result are up to date, right click and choose “Update Field”.
  • and to make sure you open every field inside a master field, select the whole field (better select the whole line containing it), right click and choose “Toggle Field Codes” (otherwise, some fields that are badly coded or that may return a void expression, may not be seen and may affect the seeing result later on when not wanted).

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}
蹲墙角沉默 2024-09-06 02:52:48

我建议计算两个日期的序列号,然后将它们相减。它不必太复杂:无论如何我们只对年数感兴趣。 年*365 + 月*31 + 日 在这里应该很好。

对于年数,将差值除以 365。然后使用 INT 去掉小数部分(不是 ROUND,这会让你在半年中老一岁)。

{ = INT(({ DATE \@"YYYY" }*365 + { DATE \@"MM" }*31 + { DATE \@"dd" } 
      - (my_year*365 + my_month*31 + my_day)) / 365) \# "0" }

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" }
北渚 2024-09-06 02:52:48
  1. 创建文本表单字段。将该字段命名为“BirthDate”

在此处输入图像描述

  1. 使用以下代码创建字段:

{={DATE \@ "yyyy"} — {BirthDate \@ "yyyy"}}

  1. Create the text form field. Name the field as "BirthDate"

enter image description here

  1. Create the field with the following code:

{={DATE \@ "yyyy"} — {BirthDate \@ "yyyy"}}

不必了 2024-09-06 02:52:48

我做了这样的事情:

10.2014 – 05.2020 (date1 - date2)
5 years, 8 months (difference)

我已将“10.2014”映射为名称为“d1”的书签(插入>书签)(稍后会派上用场。“05.2020”是“日期”(插入>字段> Date) 格式为 {DATE \@ "MM.yyyy"}。 要访问此值,RMB > 切换字段代码

下一步是计算“5 年零 8 个月”的差异。为此,我分别计算了“年”和“月”数字,有两个不同的字段,如下所示:
field1years,field2months其中

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)

它可以进一步调整以显示“year”或“years”,“month”或“months”,但对我来说就足够了。

一些进一步的解释:

  • 不要写 {}。使用Ctrl+F9插入字段
  • field2复杂化解决了10.2015和02.2020之间的差异问题

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:

  • Do not write {}. Use Ctrl+F9 to insert a field
  • field2 complications were done to solve the problem for differences between 10.2015 and 02.2020
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文