The following field expresses todays 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 cant
display date ordinals with superscripting. The second example shows how to
overcome that limitation.
メモ ワードのフィールドは通常、序数を上付きで表示することが出来ません。第2例はそれを可能にする方法です。
Julian day numbers represent the number of elapsed days since the
beginning of a cycle of 7,980 years.
ユリウス通日(つうじつ)は7,980年の周期の初日(紀元前4713年1月1日)からの連続した通し番号の経過日数です。
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.
グレゴリオ暦の紀元前4714年11月24日がユリウス通日の"0"に相当します。
The following field expresses todays 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フィールドは、ブックマークに新しい名前を割り当てるフィールドです。
The following field expresses todays 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゜MMMM゜yyyy"}
※ ゜記号は、[Ctrl]+[Shift]+[スペース]で入力する、
「改行をしないスペース」です。(段落途中での自動改行を防止します。)
Note: The Julian Day Number for this field is
taken from the previous example.
メモ:このフィールドのユリウス通日は前述の例文を採用しています。
The following field expresses todays 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"} \@ "d゜MMMM゜yyyy"}
Note: The Julian Day Number for this field is
taken from the penultimate example.
メモ:このフィールドのユリウス通日は前述の例文を採用しています。
Under the Julian calendar, Julian Day 0 is
1 January 4713 BC.
ユリウス暦において、ユリウス通日の"0"は紀元前4713年1月1日です。
The following field expresses todays 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.
メモ:このフィールドのユリウス通日は前述の例文を採用しています。これはグレゴリオ暦の変換結果と同じです。
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゜MMMM゜yyyy"}.}
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"}.}
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 todays date string from the nominated dates date string and uses a custom numeric picture switch to generate the appropriate future, past or present tense.
Although Word can express Gregorian calendar dates in a day of the week format, it apparently cant do so with Julian Day Numbers or Julian calendar dates. The following field expresses todays 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.
The following field returns the day of the year for todays Gregorian calendar date:
Todays date (Saturday 20 January 2007) falls on the 20th day of the year.
フィールドコード
{}
The following field returns the Gregorian calendar date for todays 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.
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):
November
フィールドコード
{}
November2007
フィールドコード
{}
Note: ASCII value 160 is used in this field to create a non-breaking space.
January2008
フィールドコード
{}
Wednesday, 20 February 2008
フィールドコード
{}
Friday, 20 April 2007
フィールドコード
{}
フィールドコード
{}
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.
Saturday, 17 November 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.
フィールドコード
{}
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.
フィールドコード
{}
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.
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.
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.
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, 1January2004A.D.
フィールドコード
{}
Note: This field overcomes Words 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.
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 youd use a field like:
Friday, 2 March 2007
フィールドコード
{}
Note: In the above example, youd need to add MERGEFIELD to the fields containing MergeDate (eg: {MERGEFIELD MergeDate \@ d/MM/yyyy}) and change MergeDate to your mailmerge date fields 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 fields name.
One of the limitations of Words 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:
The following field expresses todays 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
フィールドコード
{}
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
フィールドコード
{}
Note: The bookmarked dates can be in various formats, including mixed formats. Both dates must be after 31 December 1900.
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 someones 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:
フィールドコード
{}
In this field, if you need to include the StartDate (such as when calculating someones 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.
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.
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)
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.
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. Butchers 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.
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.
If
the Expiry date is
20 January 2007 then this document has
not expired.
フィールドコード
{}
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.
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.
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
フィールドコード
{}
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.]
フィールドコード
{}
Sometimes you might need to convert a date that is presented as a string (eg 20070120) into one of Words 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:
フィールドコード
{}
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.
フィールドコード
{}
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.
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.
フィールドコード
{}
フィールドコード
{}
(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 systems 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 youre using dates from before 1 March
1900, this can be ignored.