PDA

View Full Version : [SOLVED:] Date Calculation problem



RonNCmale
04-26-2015, 06:36 PM
In the attached word doc if you enter a month in the first text form field with 30 days and enter 30 in the next text form field the date displayed is incorrect. But if you enter any month without 30 days it works correctly. What am I missing? :banghead: :banghead: :banghead: :banghead:

I found out this will not work with alot of dates.

anyone have an idea to enter any date in a text form field and in another text form field enter 10; 30; 45; 60 days to give the correct date in the last text form field.

thanks for any help.

gmayor
04-26-2015, 10:12 PM
Look again at the document from where you obtained the field construction and read the part at the beginning about US date formats. The document is linked from http://www.gmayor.com/insert_a_date_other_than_today.htm


{QUOTE
{SET Delay {FmDelay}}
{SET a{=INT((14-{FmDate \@ M})/12)}}
{SET b{={FmDate \@ yyyy}+4800-a}}
{SET c{={FmDate \@ M}+12*a-3}}
{SET d{FmDate \@ d}}
{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045+Delay}}
{SET e{=INT((4*(jd+32044)+3)/146097)}}
{SET f{=jd+32044-INT(146097*e/4)}}
{SET g{=INT((4*f+3)/1461)}}
{SET h{=f-INT(1461*g/4)}}
{SET i{=INT((5*h+2)/153)}}
{SET dd{=h-INT((153*i+2)/5)+1}}
{SET mm{=i+3-12*INT(i/10)}}
{SET yy{=100*e+g-4800+INT(i/10)}}
{"{mm}-{dd}-{yy}" \@ "MMM d yyyy"}

RonNCmale
04-26-2015, 11:29 PM
Thanks so much!!!

gmaxey
04-27-2015, 06:43 AM
An alternate method is to use VBA (you would have to use a macro enabled template/document). Add a new text formfield "FmDateCalculated" Set the following macro to run on exit from FmDelay:


Sub DDOnExitDays()
With ActiveDocument.FormFields("FmDateCalculated")
.Enabled = True
.Result = Format(DateAdd("d", ActiveDocument.FormFields("FmDelay").Range.Text, Now), "MMMM, d, yyyy")
.Enabled = False
End With
End Sub