Date comparison inconsistency

T

Tosca

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
 
M

macropod

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
 
T

Tosca

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
 

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