Hi everyone
I have an Excel sheet which contains a series of dates. I have set their
format to "d MMMM yyyy". One of them is taken into Word 2003 as a field
named LastPayment. I want to compare this with a specific date (24
September 2005) and, depending upon whether the result indicated the past or
future, either "was" or "is" should be returned.
I have tried the following, but it doesn't work correctly:
{ IF { MERGEFIELD LastPayment \@ "d MMMM yyyy" } > "24 September 2005" "is"
"was" }
It works OK if the day is after 24 (i.e. "28 February 2005" returns "is",
whilst "20 December 2005" returns "was") but it doesn't examine the whole
date for the comparison.
I tried forcing 24 September 2005 to this format by adding a switch:
{ IF { MERGEFIELD LastPayment \@ "d MMMM yyyy" } > "24 September 2005 \@ d
MMMM yyyy" "is" "was" }
but this didn't make any difference, nor did it result in an error. I don't
even know if the application of a switch in this way is logical or
appropriate.
How do I change this to make the comparison work correctly?
Thanks for your time.
Tosca
macropod - 26 Sep 2005 22:57 GMT
Hi Tosca,
To compare dates with Word, you need to express them in ISO format. Try:
{IF{MERGEFIELD LastPayment \@ yyyymmdd}> 20050924 is was}
and, since you appear to be testing against the current date, you could use:
{IF{MERGEFIELD LastPayment \@ yyyymmdd}> {DATE\ @ yyyymmdd} is was}
For more information on date & time calculations in Word fields, see my
'tutorial' at:
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=249902
You'll find lots of practical pre-coded examples there.
Cheers
> Hi everyone
>
[quoted text clipped - 27 lines]
>
> Tosca
Graham Mayor - 27 Sep 2005 05:56 GMT
See the relevant section at http://www.gmayor.com/formatting_word_fields.htm

Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Hi everyone
>
[quoted text clipped - 27 lines]
>
> Tosca
Tosca - 27 Sep 2005 08:42 GMT
Thank you for the tips - I've managed to get it to work correctly. I know
from experience with Excel that date calculations tend to cause headaches
and I would never have managed to work this one out without your guidance.
Tosca