1 Insert A Date With Text Using A Formula Field
=(式)フィールドを使用した日付の挿入

The following field expresses today’s date in ordinal form, coupled with the day of the week:
次のフィールドは本日の日付を曜日と共に序数で表示しています。

Saturday the 20th of January, 2007

フィールドコード

{DATE \@ "dddd 'the {DATE \@ d \*Ordinal} of MMMM, yyyy"}

or
Saturday the 20th of January, 2007

 

フィールドコード

{QUOTE{DATE \@ "dddd 'the d"}
{IF{=(mod({DATE \@ d},10)<4)*(mod({DATE \@ d}
,10)<>0)*({DATE \@ d}<>11)*({DATE \@ d}<>12)*({DATE \@ d}<>13}
= 1 {=mod({DATE \@ d},10)-2 \# rd,st,nd} th}
{DATE \@ "' of' MMMM, yyyy" }}

QUOTEフィールドは、指定した文字列を挿入するフィールドです。

Note: Word fields ordinarily can’t display date ordinals with superscripting. The second example shows how to overcome that limitation.
メモ ワードのフィールドは通常、序数を上付きで表示することが出来ません。第2例はそれを可能にする方法です。

2 Convert a Gregorian Calendar Date to a Julian Day Number
グレゴリオ暦の日付をユリウス通日に変換

Julian day numbers represent the number of elapsed days since the beginning of a cycle of 7,980 years.
ユリウス通日(つうじつ)は7,980年の周期の初日(紀元前471311日)からの連続した通し番号の経過日数です。

This system was invented by Joseph Justus Scaliger (1540-1609) in 1582 and is typically used in astronomical calculations to overcome the fact that the solar year is not a number of whole calendar days.
ユリウス通日は、ジョセフ ジャスタス スカリゲル(1540-1609)により、1583年に考案され、数年にわたる2点の日数を計算するのに便利で、特に天文学などに使われています。

Under the Gregorian calendar, Julian Day 0 is 24 November 4714 BC.
グレゴリオ暦の紀元前47141124日がユリウス通日の"0"に相当します。

The following field expresses today’s Gregorian calendar date as a Julian Day Number:
次のフィールドは本日(グレゴリオ暦)のユリウス通日を表示しています。

2,454,121

 

フィールドコード

{QUOTE
{SET a{=INT((14-{DATE \@ M})/12}}
{SET b{={DATE \@ yyyy}+4800-a}}
{SET c{={DATE \@ M}+12*a-3}}
{SET d{DATE \@ d}}
{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}}
{jd \# ,0}}

SETフィールドは、ブックマークに新しい名前を割り当てるフィールドです。

3 Convert a Julian Day Number to a Gregorian Calendar Date
ユリウス通日をグレゴリオ暦の日付に変換

The following field expresses today’s Julian Day Number as a Gregorian calendar date:
次のフィールドは本日のユリウス通日をグレゴリオ暦の日付で表示しています。

Saturday, 20 January 2007

 

フィールドコード

{QUOTE
{
SET e{=INT((4*(jd+32044)+3)/146097)}}
{
SET f{=jd+32044-INT(146097*e/4)}}
{
SET g{=INT((4*f+3)/1461)}}
{
SET h{=f-INT(1461*g/4)}}
{
SET i{=INT((5*h+2)/153)}}
{
SET dd{=h-INT((153*i+2)/5)+1}}
{
SET mm{=i+3-12*INT(i/10)}}
{
SET yy{=100*e+g-4800+INT(i/10)}}
{
=dd*10^6+mm*10^4+yy \# "00'-'00'-'0000"} \@ "dddd, d
MMMMyyyy"}

※ ゜記号は、[Ctrl]+[Shift]+[スペース]で入力する、
「改行をしないスペース」です。(段落途中での自動改行を防止します。)

Note: The Julian Day Number for this field is taken from the previous example.
メモ:このフィールドのユリウス通日は前述の例文を採用しています。

4 Convert a Julian Day Number to a Julian Calendar Date
ユリウス通日をユリウス暦の日付に変換

The following field expresses today’s Julian Day Number as a Julian calendar date:
次のフィールドは本日のユリウス通日をユリウス暦の日付で表示しています。

1 July 2007

 

フィールドコード

{QUOTE
{SET f{=jd+32082}}
{
SET g{=INT((4*f+3)/1461)}}
{
SET h{=f-INT(1461*g/4)}}
{
SET i{=INT((5*h+2)/153)}}
{
SET dd{=h-INT((153*i+2)/5)+1}}
{
SET mm{=i+3-12*INT(i/10)}}
{
SET yy{=g-4800+INT(i/10)}}

{
=dd*10^6+mm*10^4+yy \# "00'-'00'-'0000"} \@ "dMMMMyyyy"}

Note: The Julian Day Number for this field is taken from the penultimate example.
メモ:このフィールドのユリウス通日は前述の例文を採用しています。

5 Convert a Julian Calendar Date to a Julian Day Number
ユリウス暦の日付をユリウス通日に変換

Under the Julian calendar, Julian Day 0 is 1 January 4713 BC.
ユリウス暦において、ユリウス通日の"0"は紀元前47131月1日です。

The following field expresses today’s Julian calendar date as a Julian Day Number:
次のフィールドは本日のユリウス暦の日付をユリウス通日で表示しています。

2,454,121

 

フィールドコード

{QUOTE
{SET a}{=INT((14-mm)/12)}}
{
SET b}{=yy+4800-a}}
{
SET c}{=mm+12*a-3}}
{
SET d}{=dd }}
{
SET jd}{=d+INT((153*c+2)/5)+365*b+INT(b/4)-32083}}
{
jd \# ,0}}

Note: The Julian Day Number for this field is taken from the previous example. This gives the same result as for the Gregorian calendar date conversion.
メモ:このフィールドのユリウス通日は前述の例文を採用しています。これはグレゴリオ暦の変換結果と同じです。

6 Convert a Gregorian Calendar Date to a Julian Calendar Date
グレゴリオ暦の日付をユリウス暦の日付に変換

The following field combines the conversion of a Gregorian calendar date to a Julian Day Number with a Julian Day Number to a Julian calendar date conversion to express a Gregorian calendar date as the equivalent Julian calendar date:
次のフィールドは、グレゴリオ暦の日付をユリウス通日への変換と、ユリウス通日をユリウス暦の日付への変換とを組み合わせて、グレゴリオ暦の日付をユリウス暦の日付で表しています。

Gregorian date 20 January 2007 is the same as Julian date 1 July 2007.

 

フィールドコード

{ QUOTE
{
ASK GregorianDate
"What is the Gregorian calendar date, in dd/mm/yyyy format, please?"
 \d { DATE \@ "d/MM/yyyy"}}
{
SET a{=INT((14-{GregorianDate \@ M})/12)}}
{
SET b{={ GregorianDate \@ yyyy}+4800-a}}
{
SET c{={ GregorianDate \@ M}+12*a-3}}
{
SET d{GregorianDate \@ d}}
{
SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}}
{
SET f{=jd+32082}}
{
SET g{=INT((4*f+3)/1461)}}
{
SET h{=f-INT(1461*g/4)}}
{
SET i{=INT((5*h+2)/153)}}
{
SET dd{=h-INT((153*i+2)/5)+1}}
{
SET mm{=i+3-12*INT(i/10)}}
{
SET yy{=g-4800+INT(i/10)}}
"Gregorian date { GregorianDate \@ "d MMMM yyyy"} is the same as Julian date "
{QUOTE{=dd*10^6+mm*10^4+yy \# "00'-'00'-'0000"} \@ "d
MMMMyyyy"}.}

7 Convert A Julian Calendar Date To A Gregorian Calendar Date
ユリウス暦の日付をグレゴリオ暦の日付に変換

The following field combines the conversion of a Julian calendar date to a Julian Day Number with a Julian Day Number to a Gregorian calendar date conversion to express a Julian calendar date as the equivalent Gregorian calendar date:
次のフィールドは、ユリウス暦の日付をユリウス通日への変換と、ユリウス通日をグレゴリオ暦の日付への変換とを組み合わせて、ユリウス暦の日付をグレゴリオ暦の日付で表しています。

Julian date 20 January 2007 is the same as Gregorian date 2 February 2007.

 

フィールドコード

{ QUOTE
{ ASK JulianDate
"What is the Julian calendar date, in dd/mm/yyyy format, please?"
 \d { DATE \@ dd/MM/yyyy}}
{
SET d{JulianDate \@ d}}
{
SET m{JulianDate \@ M}}
{
SET y{JulianDate \@ yyyy}}
{
SET a{=INT((14-m)/12) }}
{
SET b{=y+4800-a}}
{
SET c{=m+12*a-3}}
{
SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-32083}}
{
SET e{=INT((4*(jd+32044)+3)/146097)}}
{
SET f{=jd+32044-INT(146097*e/4)}}
{
SET g{=INT((4*f+3)/1461)}}
{
SET h{=f-INT(1461*g/4)}}
{
SET i{=INT((5*h+2)/153)}}
{
SET dd{=h-INT((153*i+2)/5)+1}}
{
SET mm{=i+3-12*INT(i/10)}}
{
SET yy{=100*e+g-4800+INT(i/10)}}
"Julian date {JulianDate \@ "d MMMM yyyy"} is the same as Gregorian date "
{QUOTE{=dd*10^6+mm*10^4+yy \# "00'-'00'-'0000"{ \@ "d MMMM yyyy"}.}

8 Find The Day Of The Week Of A Gregorian Calendar Date
グレゴリオ暦の日付の曜日を調べる

The following field returns the day of the week for a nominated date:
次のフィールドは指定した日付の曜日を返しています。

20 January 2007 is a Saturday.

 

フィールドコード

{QUOTE
{ASK AskDate
"What is date do you want the weekday for, in dd/mm/yyyy format, please?"
 \d { DATE \@ "d/MM/yyyy"}}
{
AskDate \@ "d MMMM yyyy"}
{
={AskDate \@ YYYYMMdd}-{DATE \@ YYYYMMdd} \# \ will\ be\ a\ ;\ was\ a\ ;\ is\ a\ }
{
AskDate \@ dddd}."}

Note: This field shows how you can compare two dates in Word, by expressing them in ISO format. In this example, the field subtracts today’s date string from the nominated date’s date string and uses a custom numeric picture switch to generate the appropriate future, past or present tense.

9 Convert A Julian Day Number Or Julian Date To A Day Of The Week
ユリウス通日またはユリウス暦の日付を曜日に変換

Although Word can express Gregorian calendar dates in a day of the week format, it apparently can’t do so with Julian Day Numbers or Julian calendar dates. The following field expresses today’s Julian Day Number as a day of the week:

Friday

 

フィールドコード

{QUOTE
{IF{=MOD(jd,7)}
= 0 Mon
{IF{=MOD(jd,7)}
= 1 Tues {IF{=MOD(jd,7)}
= 2 Wednes {IF{=MOD(jd,7)}
= 3 Thurs {IF{=MOD(jd,7)}
= 4 Fri {IF{=MOD(jd,7)}
= 5 Satur Sun}}}}}}day}

Thus, if you convert a Julian calendar date to a Julian Day Number, you can find the corresponding day of the week.

Note: The Julian Day Number for this field is taken from the previous example.

10 Find The Day Of The Year For A Given Date
その日付の年初からの通算日を調べる

The following field returns the day of the year for today’s Gregorian calendar date:

Today’s date (Saturday 20 January 2007) falls on the 20th day of the year.

 

フィールドコード

{}

11 Find The Date For A Given Day Of The Year
年初からの通算日の日付を調べる

The following field returns the Gregorian calendar date for today’s day of the year:

Day 20 in 2007 falls on
Friday, 2 November.

 

フィールドコード

{}

Note: The day of the year for this field is taken from the previous example.

12 Automatically Insert A Past Or Future Date
過去または未来の日付の自動挿入

The following fields calculate any past or future date from today, based on the Gregorian calendar. Setting the “Delay” variable in the fields allows for the required date to be many days, months and/or years ahead or behind (the latter is achieved by expressing the “Delay” variable as a negative number):

-1 Calculate a month, using n months delay

November

 

フィールドコード

{}

-2 Calculate a month and year, using n months delay

November2007

 

フィールドコード

{}

Note: ASCII value 160 is used in this field to create a non-breaking space.

-3 Calculate a month and year, using n years delay

January2008

 

フィールドコード

{}

-4 Calculate a day, date, month and year, using n years delay

Wednesday, 20 February 2008

 

フィールドコード

{}

-5 Calculate a day, date, month and year, using n months delay

Friday, 20 April 2007

 

フィールドコード

{}

-6 Calculate a lease expiry date, using n months delay

Saturday, 19 January 2008

 

フィールドコード

{}

-7 Calculate a day, date, month and year, using n days delay

Friday, 2 March 2007

 

フィールドコード

{}

Note: To work with dates before 1 January 1901 or after 31 December 4095, see ”14 Working With Dates Before 1 Jan 1901 Or After 31 Dec 4095”, below.

-8 Calculate a day, date, month and year, using n weeks delay

Saturday, 17 November 2007

 

フィールドコード

{}

-9 Calculate the day & date of the last or nth-to-last day of this month

Wednesday, 31 January 2007

 

フィールドコード

{}

Note: Increasing the ‘Subtract’ variable returns the nth-to last day of the month (eg Subtract = 0 gives the last day of the month, while Subtract = 1 gives the second-last day of the month). The field includes code to ensure that the calculated day does not precede the 1st of the month.

-10 Calculate the day & date of the nth day of next month

Tuesday, 2 January 2007

 

フィールドコード

{}

Note: Increasing the ‘day’ variable returns the nth day of this month (eg day = 1 gives the 1st of the month, whilst day = 2 gives the 2nd of the month, and so on). The field includes code to ensure that the calculated date does not exceed the last day of next month.

-11 Calculate the day & date of a given day of the week next month

Thursday, 25 January 2007

 

フィールドコード

{}

Note: The value in {SET Weekday 3} determines the day of the week to return (0 = Mon, 1 = Tues, 2 = Wed, 3 =  Thurs, 4 = Fri, 5 = Sat, 6 = Sun), while the value in {SET Week 1} allows you to specify the week of the month. The ‘Limit’ variable is used to prevent the chosen date rolling over into the following month. This also means that setting the Week variable to 5 will always return the last instance of a given weekday occurring in a month.

-12 Changing document dates during the course of a day

The following field increments the DATE once the time reaches 1pm. If the field is updated at or after 1p.m. on a Friday, the date updates to the following Monday.

Saturday, 20 January 2007

 

フィールドコード

{}

To change the time of day, edit the ‘>12’ variable in the Delay statement. To change the Friday to Monday day-skip, edit (or delete the ‘+(MOD(jd,7)=4)*2’ variable: The ‘=4’ determines the day of the week to work from (0 = Mon, 1 = Tues, 2 = Wed, 3 =  Thurs, 4 = Fri, 5 = Sat, 6 = Sun) and the ‘*2’ expression determines the number of days to skip.

13 Interactively Calculate A Past Or Future Date
過去または未来の日付の相互計算

The following examples use ‘ASK’ to solicit the starting date and the delay to calculate any past or future Gregorian calendar date from a specified date, according to the number of days’ delay specified:

If the starting date is Saturday, 20 January 2007
 and the offset is 1 day
, then the new date is
Sunday, 21 January 2007.

 

フィールドコード

{}

Note: The field includes a test for whether the delay equals +/- 1 day, plus error-checking code to validate the input.

or:

The starting date is
Monday, 1 January 2001.
The offset is 1 day.
The new date is
Thursday, 1 February 2001.

 

フィールドコード

{}

or:

The starting date is
Monday, 1 January 2001..

 

フィールドコード

{}
The offset is
1 day.

 

フィールドコード

{}
The new date is
Thursday, 1 February 2001..

 

フィールドコード

{}

Note: In the last of these examples, the fields are independent of each other and the two rows do not automatically update when the starting date or delay is changed. Wrapping the related fields with a QUOTE field, as in the penultimate example, overcomes this.

14 Working With Dates Before 1 Jan 1901 Or After 31 Dec 4095
1901
11日以前または40951231日以降の日付について

If either date in a calculation could precede 1 January 1901 or follow 31 December 4095, the following field can be used. It also takes account of the switch in calendars in 1582, when Thursday 4th October 1582 (Julian) was followed by Friday 15th October 1582 (Gregorian). No attempt has been made to deal with the leap-year confusion between 45 B.C. and 8 A.D.

If the starting date is Monday, 1January4713B.C. and the offset is
2,453,006
days, then the new date is Thursday, 1
January2004A.D.

 

フィールドコード

{}

Note: This field overcomes Word’s inability to recognise dates before 1 January 1901 and after 31 December 4095 by parsing the input date into day month & year numbers, instead of treating the input as a date. So, it is important to enter the date in the required format. The parsing is done mathematically, since Word fields lack string functions. As well as testing for the calendar change in 1582, the field shows how to get a ‘correct’ B.C. result; years before 1 A.D. are years B.C. (there was no 0 B.C. or 0 A.D.) and ‘1' is thus subtracted from their year value.

15 Date Calculations In A Mailmerge

You can use any of the fields in from ‘12 Automatically Insert A Past Or Future Date’ in a mailmerge. All you need to do is to add a call to your mailmerge field and change the various ‘DATE’ references to suit.

For example, to do a date calculation in a mailmerge with an imported mergedate of
20 Jan 2007

フィールドコード

{}

 and a 14-day delay you’d use a field like:

Friday, 2 March 2007

 

フィールドコード

{}

Note: In the above example, you’d need to add ‘MERGEFIELD’ to the fields containing ‘MergeDate’ (eg: {MERGEFIELD MergeDate \@ d/MM/yyyy}) and change ‘MergeDate’ to your mailmerge date field’s name. Plus, if the delay was being imported as part of the mailmerge, you could also replace {SET Delay 14} with {SET Delay{MERGEFIELD MergeDelay \# 0}}, again changing ‘MergeDelay’ to your mailmerge delay field’s name.

16 Date Calculations in a Table

One of the limitations of Word’s formula handling in tables is its inability to evaluate text strings, including dates. To get around this, you need to bookmark the contents of the affected cells (not the cells themselves) and reference those bookmarks (instead of the cells) in the formula. The following table demonstrates how to do this using ASK fields to create the bookmarks:

Monday, 1-Jan-2001

25

Friday, 26 January 2001

フィールドコード

フィールドコード

フィールドコード

{}

{}

{}

17 Express Today’s Date in Fiscal Year Terms

The following field expresses today’s date in fiscal year terms, showing the year, month #, and week # within the month, assuming a 1 July to 30 June fiscal year:

Fiscal Year 07/08
, Month: 7, Week:
3

 

フィールドコード

{}

18 Calculate the # Days Difference Between Two Dates

The following field subtracts the date in the StartDate bookmark (from a previous field) from the date in the EndDate bookmark (turn ‘show bookmarks’ on to see it), and returns the number of days’ difference as a +ve or –ve value:

StartDate:    1 January 2001
                  
フィールドコード
                   {}

EndDate:      30 June 2002

Days Difference:    545

フィールドコード

                            {}

Note: The bookmarked dates can be in various formats, including mixed formats. Both dates must be after 31 December 1900.

19 Calculate the # Years Months & Days Difference Between Two Dates

There are two approaches that one might take to this issue, depending on whether you need a calendar-based approach, which takes account of the start/end dates, or an approximation based on the number of days’ difference between two dates.

The approximation approach below is based on a dividing the number of days difference between the StartDate and the EndDate (ie EndDate-StartDate=Period) into a nominal number of years, months and days without regard to the actual months concerned or whether the start or end year is a leap year:

1 Year, 5 Months
, 28 Days.

 

フィールドコード

{}

In this field, if you need to include the StartDate (such as when calculating someone’s period of employment), increase the Period by 1.

The equivalent date-based field, in which the calculation is based on the actual calendar dates, is:

1 Year
, 5 Months, 29 Days.

 

フィールドコード

{}

In this field, if you need to include the StartDate (such as when calculating someone’s period of employment), change the {SET sd {StartDate \@ d}} to {SET sd {={StartDate \@ d}-1}}.

Note: Both of the above fields get their dates from the previous example.

20 Interactively Calculate A Person’s Age

The following field uses an ASK field for date of birth input and uses this to perform an age calculation:

If your Date of Birth was 1 January 1901
, then your age is 106 Years, 0 Months and 19 Days.

 

フィールドコード

{}

Note: The field includes error-checking code to validate the input.

21 Calculate a Stepped Date

The following field calculates a predetermined weekly date (in this case, [next] Sunday).

Sunday, 21 January 2007

 

フィールドコード

{}

Note: To change the day of the week on which the calculated result is based, change the 6 in the statement {SET Weekday 6} to suit, using:
(0 = Mon, 1 = Tues, 2 = Wed, 3 =  Thurs, 4 = Fri, 5 = Sat, 6 = Sun)

22 Calculate a Stepped Date Range

The following field calculates a date range that goes from the Thursday of this week through to Wednesday of next week. This would be useful in a template used for the creation of weekly reports.

Thursday, 18 January 2007 through Wednesday, 24 January 2007

 

フィールドコード

{}

Note: As with the previous example, change the 3 in the statement {SET Weekday 3} to suit the day of the week on which the calculated result is based. For a fortnightly report, change the 7s in the statement {SET jd{=INT((jd)/7)*7+Weekday}} to 14 and change the 6 in the statement {SET Delay 6} to 13. You may also need to add 7 to the statement {SET Weekday 3} for a fortnightly report, so as to select the correct starting week. Note also the use of ASCII 32 to create the text spaces.

23 Calculate Dates Of Easter

The following field uses an algorithm developed by Samuel Butcher, Bishop of Meath, to calculate dates of Easter for Western churches – Orthodox churches use a different algorithm, with different results. Butcher’s algorithm holds for any year in the Gregorian calendar, (i.e. years since 1582):

In 2007, the Western Easter Sunday
falls on the (Gregorian) 8th of April.

 

フィールドコード

{}

Note: This field includes a test for whether the event has past. You could also combine this field with an IF test and the equivalent Julian calendar calculations (see the next example) to get valid Western Easter dates for 1582 and earlier.

Orthodox churches celebrate Easter on the basis of the Julian calendar. Until the Gregorian calendar was introduced in 1582, Orthodox churches celebrated Easter Sunday on the same date as Western churches. Since then, the Orthodox churches have often celebrated Easter Sunday on different dates from Western churches. In some years the Orthodox Easter Sunday occurs on the same day as the Western Easter Sunday. In most years, however, Orthodox Easter follows Western Easter by at least one week. Calculating the Orthodox date of Easter is much simpler than the Western date of Easter:

In the same year, the Orthodox Easter Sunday
falls on the (Julian) 26th
 of March. This equates to the (Gregorian) 8th of April.

 

フィールドコード

{}

Note: This field uses the year from the previous example, and adds a Julian to Gregorian calendar conversion.

For those who are interested about the Orthodox Easter date calculation:
G is the so-called
“Golden Number”-1
I is the number of days from 21 March to the Paschal full moon
J is the weekday of the Paschal full moon (0=Sunday, 1=Monday, etc.)
I-J is the number of days from 21 March to the Sunday on or before the Paschal full moon.

24 Use Date (And/Or Time) Comparisons To Vary Text

Sometimes you might need to compare two dates so as to determine which is the greater. For example, you might need to test whether a certain date has passed and use the result of the test to trigger an expiry notice. The simplest way to do such a test is to express the dates to be compared in ISO format (ie yyyyMMdd) and compare the two – or subtract one from the other – as in the following examples, some of which extend this scheme to include hours and minutes.

Determine whether a document has expired

If the Expiry date is
20 January 2007 then this document has
not expired.

 

フィールドコード

{}

Use a date test to provide pre-printing instructions

By placing a field like the following in a document, you can provide user instructions that will disappear permanently the first time the document is printed:

As shown, each of the paragraphs can have their own styles, so that the instructions appear properly formatted.

Hide instructions at print time

An alternative to the previous example would be to hide the field whenever the document is printed, but allow it to be restored later. The following field does just that:

Your instructions go here.

 

フィールドコード

{}

Pressing F9 or print preview restores the field. The only limitation is that the PRINTDATE field doesn't support seconds, so you might have to wait up to a minute before you can restore the field.

Vary instructions & prompts, based on Print/Save Dates

A variation on the previous example could be to compare the PRINTDATE and SAVEDATE or DATE values and to display different instructions depending on whether the document has been printed since it was last saved or since it was opened, respectively. For example:

Not Printed Since Last Save

 

フィールドコード

{}

Vary text in a document , based on Print/Save Dates and the user’s name

The next field (within the square brackets) remains invisible until the document is printed, by way of a PRINTDATE test, and only prints if the user's name (UserName) isn't "My Name". The UserName is whatever appears under Tools|Options|User Information.

[This Document Expires 5 days after
10 January 2007.
]

 

フィールドコード

{}

25 Converting Date Strings Into Word Date Formats

Sometimes you might need to convert a date that is presented as a string (eg 20070120) into one of Word’s date formats. Such string formats sometimes appear in mailmerge source files. The following fields show how you can do this conversion (using ASK fields instead of MAILMERGE fields):

Saturday, 20 January 2007

 

フィールドコード

{}

To format to a date string with an ordinal day number you could use a field coded like:

Saturday, 20th January 2007

 

フィールドコード

{}
or, for a superscripting of the ordinal expression:

Saturday, 20th January 2007

 

フィールドコード

{}

26 Importing Date and Time Values From Excel and Access

Excel and Access store dates as the number of days that have elapsed since 31/12/1899[1], whilst times are converted into the number of seconds since midnight and then divided by 86,400 (the number of seconds in a day) to calculate a decimal time value. Thus, a combined date and time field has an integer part to represent the date and a decimal part to represent the time of day.

For example, the date 1 January 2000 is stored as 36,526, whilst the time 12:13:14pm is stored as 0.5091898148, because 12 hours (43,200 seconds) plus 13 minutes (780 seconds) plus 14 seconds equals 43,994 seconds and this, divided by 24 hours (86,400 seconds), equals 0.5091898148. Thus, 1 January 2000 12:12:12 is stored as 36526.5091898148.

So, if you import a numeric date/time value into Word from Excel or Access, how can you use it? You do so by separating the Excel or Access date/time value into its integer and decimal parts, then adding the integer part to the date 31/12/1899 to calculate the new date and multiplying the decimal part by 86,400 so that the number of seconds can be converted to a time value.

To illustrate, let the ImportValue = 36526.5091898148. The field to turn this into a time, day and date in Word is:

Saturday, 1 January 2000 @ 12:13:14

 

フィールドコード

{}

 or
Saturday, 1 January 2000 @ 12:13:14p.m.

 

フィールドコード

{}

27 Add Or Subtract Two Time Periods

The following field calculates the sum of two time periods:
a)       to a maximum of 24 hours each:
36:19:56;

 

フィールドコード

{}

b)       if you need to use more than 24 hours for either time:
48:19:56; or

フィールドコード

{}

c)       if you need to use more than 24 hours for both times:
60:19:56

フィールドコード

{}

The following field calculates the difference between two time periods:
a)       to a maximum of 24 hours each:
11:10:04;

フィールドコード

{}

b)       if you need to use more than 24 hours for either time:
-00:49:56;

フィールドコード

{}

or
c)       if you need to use more than 24 hours for both times: :
11:10:04.

フィールドコード

{}

Note: A minor variation on the last of the additions can be used for both addition and subtraction, by requiring the subtraction time components to be input as negative values.

28 Automatically Calculate A Past Or Future Time of Day

The following field calculates a future time of day from now, according to the number of hours, minutes and seconds delay specified, to a maximum of 24 hours, allowing also for the possibility that the new time might be sometime tomorrow:

7:27:06p.m.

フィールドコード

{}

 or

19:27:06

フィールドコード

{}

 (military time).

The following field calculates a past time of day from now, according to the number of hours, minutes and seconds delay specified to a maximum of 24 hours, allowing also for the possibility that the new time might be sometime yesterday:

-03:42:46a.m.

フィールドコード

{}

 or
-15:42:46

フィールドコード

{}

 (military time).

Note: The same techniques that were employed to add or subtract two time periods can be used here also if the source time periods might exceed 24 hours. Also note that the a.m./p.m. designations used here are independent of your system’s regional settings.

 



[1] Actually, for compatibility purposes Excel replicated a bug in Lotus 123, which had day 1 as 1 January 1900 but wrongly treated that year as a leap year. Unless you’re using dates from before 1 March 1900, this can be ignored.