Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / September 2005

Tip: Looking for answers? Try searching our database.

Date comparison inconsistency

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tosca - 26 Sep 2005 22:46 GMT
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

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.