How do I compare dates in a Word IF field?

M

Marion G

I want to compare a specific date with a date coming in via a MERGEFIELD.
I've set it up as {IF "12/12/2005" > {MERGEFIELD DATE} "Static date is later"
"Static date is earlier"}. What's happening is the opposite of what I expect.
My MERGEFIELD DATE is 12/12/2004 and the field results are showing "Static
date is earlier". If I change the static date to "12/12/03", I get "Static
date is later". I suppose I could get around it by doing the opposite to what
I think is logical, but I'd really like to understand what's going on. Can
someone help please?
 
J

Jezebel

There are two issues. First, the comparison Word is making is a *string*
comparison, not a date comparison. It's comparing the string "12/12/2005"
with the date *representation* returned by your merging, which will depend
on your regional settings. In other words, it can't work like this. Word
can't directly do date arithmetic or comparisons in fields.

The simplest method for your purposes is to modify the merge query to
include the decision:

SELECT IIF([DateField] < #2005-12-12#, "Earlier", "Later") as DateStatus
.....

Alternatively, you could run a macro on completion to update the display.


Or for a third option, Macropod will probably suggest his/her wierd and
wonderful field hacks. Bear in mind that these are indeed hacks, and M's
furious imprecations notwithstanding, shouldn't be used for any serious
purpose.
 

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