Reply
 
Thread Tools Display Modes
  #1   Report Post  
Marion G
 
Posts: n/a
Default How do I compare dates in a Word IF field?

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?
  #2   Report Post  
Jezebel
 
Posts: n/a
Default

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.




"Marion G" Marion wrote in message
...
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?



  #3   Report Post  
Graham Mayor
 
Posts: n/a
Default

See the relevant section at which demonstrates this using fields -
http://www.gmayor.com/formatting_word_fields.htm

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Marion G wrote:
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?



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I divide a page into three sections? Bonnie Microsoft Word Help 3 May 8th 23 02:47 AM
saving the workspace Mike Microsoft Word Help 3 December 8th 04 11:32 PM
How do I insert and format part of a data field in a Word document Graham Blundell Microsoft Word Help 4 December 1st 04 02:51 PM
How does Word compare to its contemporaries? PoniKika Microsoft Word Help 2 November 27th 04 09:16 PM
How do I make a word document insert consequative dates on each p. Luvmysuv Microsoft Word Help 1 November 24th 04 12:30 AM


All times are GMT +1. The time now is 04:35 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"