Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jul 2010
    Location
    EST
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a requirement to find if
    1. Date A + 6 months or
    2. Date B - 3 months

    To pick which ever is earliest. I am using an if/else conditionality and is not working. However I tested if -3 (Date -3 months) or Date +6 months is working individually and that works fine. Only when you do a comparision, always it is resolving as Sail Date < Date and result is the -3 date.THE WORD DOCUMENT IS ATTACHED AS WELL

    {IF
    {QUOTE
    {SET DELAY -3}
    {SET M{=MOD({SAILDT \@ MM}+DELAY+11,12)+1}}
    {SET Y{=INT({SAILDT \@ YYYY}+DELAY+{SAILDT \@ M}-1)/12}}
    {SET d{=INT({SAILDT \@ dd}}}
    "{m}-{d}-{y}" \@ "MM/DD/yyyy"}
    <
    {QUOTE
    {SET DELAY 6}
    {SET M{=MOD({DATE \@ MM}+DELAY+11,12)+1}}
    {SET Y{=INT({DATE \@ YYYY}+DELAY+{DATE \@ M}-1)/12}}
    {SET d{=INT({DATE \@ dd}}}
    "{m}-{d}-{y}" \@ "MM/DD/yyyy"}
    THEN
    {QUOTE
    {SET DELAY -3}
    {SET M{=MOD({SAILDT \@ MM}+DELAY+11,12)+1}}
    {SET Y{=INT({SAILDT \@ YYYY}+DELAY+{SAILDT \@ M}-1)/12}}
    {SET d{=INT({SAILDT \@ dd}}}
    "{m}-{d}-{y}" \@ "MM/DD/yyyy"}
    ELSE
    {QUOTE
    {SET DELAY 6}
    {SET M{=MOD({DATE \@ MM}+DELAY+11,12)+1}}
    {SET Y{=INT({DATE \@ YYYY}+DELAY+{DATE \@ M}-1)/12}}
    {SET d{=INT({DATE \@ dd}}}
    "{m}-{d}-{y}" \@ "MM/DD/yyyy"}
    }

    the result is always sail date - 3 months..

    appreciate your help at coolchandra at gmail dot com
    Attached Files Attached Files

  2. #2
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,186
    Thanks
    47
    Thanked 983 Times in 913 Posts
    It seems to me you are not comparing apples with apples (I'm not used to code in Word so I may be wrong). I would convert the current date and the sail date to standard values, then perform the calculation, rather than convert every time you calculate.

    Use the year as a whole number and add the number of days as a percentage of the year. e.g. 25 January 2010 = 2010 + (365/25).
    3 and 6 months are easy, 0.25 and 0.5.
    Now the calculation will be correct and you can work out the logic as required.

    cheers, Paul

  3. #3
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,186
    Thanks
    47
    Thanked 983 Times in 913 Posts
    Code:
    {QUOTE
    "Today’s date ({DATE \@ "dddd d*MMMM*yyyy"}) falls on the "
    {SET yd{={DATE \@ d}+INT(({DATE \@ M}-0.986)*30.575)-
    IF({DATE \@ M}>2,2-(MOD({DATE \@ yy},4)=0)-
    (MOD({DATE \@ yyyy},400)=0)+(MOD({DATE \@ yy},100)=0),0)}}
    {=yd \# 0}
    {IF{=(MOD(yd,10)<4)*(MOD(yd,10)<>0)*(MOD(yd,100)<>11)*(MOD(yd,100)<>12)*
    (MOD(yd,100)<>13)}= 1 {=MOD(yd,10)-2 \# rd;st;nd} th}" day of the year."}
    From DateCalc.zip
    EDIT: For the latest version of macropod's Date Calculations document, bookmark this thread: [topic=249902]Word Date Calculation Tutorial (v2.85)[/topic].

    cheers, Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •