以ms word计算两个日期之间的天数 [英] Calculate the amount of days between two dates in ms word

查看:62
本文介绍了以ms word计算两个日期之间的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个合并域的 Word 文档,每个域包含一个日期

I have a Word document with two mergefields, each containing a date

{ MERGEFIELD myObj.startDate \* MERGEFORMAT }--> 输出 01.01.2014

{ MERGEFIELD myObj.endDate \* MERGEFORMAT } --> 输出 31.01.2014

现在我想计算这两个日期之间有多少天,所以我必须从 endDate 中减去"startDate,例如31.01.2014 - 01.01.2014 --> 31

Now I would like to calculate how many days there are between those two dates, so I have to "substract" startDate from endDate, e.g. 31.01.2014 - 01.01.2014 --> 31

不幸的是,这不起作用:{ { MERGEFIELD myObj.endDate \* MERGEFORMAT } - { MERGEFIELD myObj.startDate \* MERGEFORMAT } }

Unfortunately this doesn't work: { { MERGEFIELD myObj.endDate \* MERGEFORMAT } - { MERGEFIELD myObj.startDate \* MERGEFORMAT } }

有谁知道这是否可能,如果有,怎么做?

Does anyone know if it's even possible, and if so, how?

推荐答案

以下解决方案摘自 Paul Edstein 发布到 Windows Secrets 论坛的文档.它包含有关如何在 Word 字段代码中执行日期计算的大量信息,可以在此线程中找到:

The solution below was taken from a document posted to the Windows Secrets forum by Paul Edstein. It contains a trove of information on how to perform date calculations in Word field codes and can be found in this thread:

Microsoft Word 日期计算教程

因为 Word 域代码不容易复制和粘贴,所以我插入了下面代码的屏幕截图.我建议您成为免费的 Windows Secrets 论坛的成员,以便您可以下载此文档并将 Edstein 先生原始文档中的域代码复制到您自己的文档中,因为这比键入文本并手动创建域代码括号更容易(Word 中的 CTRL-F9).

Because Word field codes do not copy and paste easily, I have inserted a screen cap of the code below. I suggest that you become a member of the free Windows Secrets forum so you can download this document and copy the field codes from Mr. Edstein's original document into your own document as this will be easier than keyboarding the text and creating the field code brackets manually (CTRL-F9 in Word).

以下代码应该适用于您的 DD.MM.YYYY 日期格式.如果您使用 StartDateEndDate 书签在文档中为 myObj.startDatemyObj.endDate 域代码添加书签名称,下面的代码将按原样工作.由于 SET 命令旨在与书签一起使用,因此如果您将本示例中的 EndDateStartDate 书签替换为您的 MERGEFIELD 域代码.不过这个我没有试验过,所以不知道对象模型有没有这个灵活性.

The following code should work with your date format of DD.MM.YYYY. If you bookmark your myObj.startDate and myObj.endDate field codes within your document using the StartDate and EndDate bookmark names, the code below will work as is. Because the SET command is designed to work with bookmarks, this solution will probably not work if you replace the EndDate and StartDate bookmarks from this example with your MERGEFIELD field codes. However, I have not experimented with this, so I do not know if the object model has this flexibility.

这篇关于以ms word计算两个日期之间的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆