Calculating Date Fields

B

Bigfoot17

I have a document that is filled with FormFields and users go from field to
field filling the fields for a final document. I have been reading up on
'calculated dates' but have not seen a scenario like this.

Three of my formfields are "Date1", "Date2" and "Date180." What I am trying
to figure out is how to evaluate/compare Date1 and Date2 to see which is the
earliest and then provide in Date180 the date 180 days from the earliest
date. (Unless the form is blank there will always be a Date1, but there may
not be a Date2 and if Date2 exists it is prior to Date1).

Here is what I think is the logic (not the syntax):
If Date2 > 0 then
Date180 = Date2 + 180
elseif Date1 > 0 then
Date180 = Date1 + 180
else Date180 = ""
Endif

Not only can't I figure out how to write this I do not know how to get it
display the Date180. Can this be reduced to a calulated field formula? Must
it be a macro? Any guidance is appreciated.
 
M

macropod

Hi Bigfoot17,

To see how to do the basic Dte180 calculation, check out my Microsoft Word Date Calculation Tutorial, at:
http://lounge.windowssecrets.com/index.php?showtopic=249902
or
http://www.gmayor.com/downloads.htm#Third_party
Do read the document's introductory material.

To set a StartDate value equal to the lesser of the two dates, simply use a field construction like:
{SET StartDate {={DATE1 \@ "YYYYMMDD"}>{DATE2 \@ "YYYYMMDD"} \# "'{DATE1}';;'{DATE2}'"}}
You could incorporate this into, say, the 'Calculate a day, date, month and year, using n days delay' example from the tutorial,
thus:
{QUOTE
{SET StartDate {={DATE1 \@ "YYYYMMDD"}>{DATE2 \@ "YYYYMMDD"} \# "'{DATE1}';;'{DATE2}'"}}
{SET Delay 180}
{SET a{=INT((14-{DATE \@ M})/12)}}
{SET b{={StartDate \@ yyyy}+4800-a}}
{SET c{={StartDate \@ M}+12*a-3}}
{SET d{StartDate \@ d}}
etc
 
B

Bigfoot17

I have been geting an error: "Error! Too many picture switches defined."
This is probably something I am doing but I thought I ought to check before I
age too quickly.

macropod said:
Hi Bigfoot17,

To see how to do the basic Dte180 calculation, check out my Microsoft Word Date Calculation Tutorial, at:
http://lounge.windowssecrets.com/index.php?showtopic=249902
or
http://www.gmayor.com/downloads.htm#Third_party
Do read the document's introductory material.

To set a StartDate value equal to the lesser of the two dates, simply use a field construction like:
{SET StartDate {={DATE1 \@ "YYYYMMDD"}>{DATE2 \@ "YYYYMMDD"} \# "'{DATE1}';;'{DATE2}'"}}
You could incorporate this into, say, the 'Calculate a day, date, month and year, using n days delay' example from the tutorial,
thus:
{QUOTE
{SET StartDate {={DATE1 \@ "YYYYMMDD"}>{DATE2 \@ "YYYYMMDD"} \# "'{DATE1}';;'{DATE2}'"}}
{SET Delay 180}
{SET a{=INT((14-{DATE \@ M})/12)}}
{SET b{={StartDate \@ yyyy}+4800-a}}
{SET c{={StartDate \@ M}+12*a-3}}
{SET d{StartDate \@ d}}
etc

--
Cheers
macropod
[Microsoft MVP - Word]


Bigfoot17 said:
I have a document that is filled with FormFields and users go from field to
field filling the fields for a final document. I have been reading up on
'calculated dates' but have not seen a scenario like this.

Three of my formfields are "Date1", "Date2" and "Date180." What I am trying
to figure out is how to evaluate/compare Date1 and Date2 to see which is the
earliest and then provide in Date180 the date 180 days from the earliest
date. (Unless the form is blank there will always be a Date1, but there may
not be a Date2 and if Date2 exists it is prior to Date1).

Here is what I think is the logic (not the syntax):
If Date2 > 0 then
Date180 = Date2 + 180
elseif Date1 > 0 then
Date180 = Date1 + 180
else Date180 = ""
Endif

Not only can't I figure out how to write this I do not know how to get it
display the Date180. Can this be reduced to a calulated field formula? Must
it be a macro? Any guidance is appreciated.

.
 
M

macropod

Hi Bigfoot17,

There are only three picture switches in the SET StartDate code I gave you, and they're in separate fields (ie one per field), so
that's not the source of your problem. Evidently you have some other coding error. Did you ensure to create all the field brace
pairs (ie '{}') via Ctrl-F9? Note also that there a both single and double quotes used in the final switch, which has the two date
fields embedded in it (ie \# "'{DATE1}';;'{DATE2}'").

--
Cheers
macropod
[Microsoft MVP - Word]


Bigfoot17 said:
I have been geting an error: "Error! Too many picture switches defined."
This is probably something I am doing but I thought I ought to check before I
age too quickly.

macropod said:
Hi Bigfoot17,

To see how to do the basic Dte180 calculation, check out my Microsoft Word Date Calculation Tutorial, at:
http://lounge.windowssecrets.com/index.php?showtopic=249902
or
http://www.gmayor.com/downloads.htm#Third_party
Do read the document's introductory material.

To set a StartDate value equal to the lesser of the two dates, simply use a field construction like:
{SET StartDate {={DATE1 \@ "YYYYMMDD"}>{DATE2 \@ "YYYYMMDD"} \# "'{DATE1}';;'{DATE2}'"}}
You could incorporate this into, say, the 'Calculate a day, date, month and year, using n days delay' example from the tutorial,
thus:
{QUOTE
{SET StartDate {={DATE1 \@ "YYYYMMDD"}>{DATE2 \@ "YYYYMMDD"} \# "'{DATE1}';;'{DATE2}'"}}
{SET Delay 180}
{SET a{=INT((14-{DATE \@ M})/12)}}
{SET b{={StartDate \@ yyyy}+4800-a}}
{SET c{={StartDate \@ M}+12*a-3}}
{SET d{StartDate \@ d}}
etc

--
Cheers
macropod
[Microsoft MVP - Word]


Bigfoot17 said:
I have a document that is filled with FormFields and users go from field to
field filling the fields for a final document. I have been reading up on
'calculated dates' but have not seen a scenario like this.

Three of my formfields are "Date1", "Date2" and "Date180." What I am trying
to figure out is how to evaluate/compare Date1 and Date2 to see which is the
earliest and then provide in Date180 the date 180 days from the earliest
date. (Unless the form is blank there will always be a Date1, but there may
not be a Date2 and if Date2 exists it is prior to Date1).

Here is what I think is the logic (not the syntax):
If Date2 > 0 then
Date180 = Date2 + 180
elseif Date1 > 0 then
Date180 = Date1 + 180
else Date180 = ""
Endif

Not only can't I figure out how to write this I do not know how to get it
display the Date180. Can this be reduced to a calulated field formula? Must
it be a macro? Any guidance is appreciated.

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top