Expand my Community achievements bar.

Date Time Field

Avatar

Former Community Member
Hi

I have two DateTime Fields



I need show the firs date (DateTime1) + one month in DateTime2, usin change event



Example

In dateTime1 have 2006/05/13



I need see im DateTime2 2006/06/13



Who is that?

Thanks
3 Replies

Avatar

Former Community Member
If you can use javascript date object, you can call getMonth() and getFullYear() to do that.

Henry

Avatar

Level 5
check the following FormCalc code....use this in 'exit' event.



var givenDate

var myDate

var daysToAdd

var interDateNum

givenDate = IsoDate2Num($.rawValue)

daysToAdd = 30

interDateNum = givenDate +daysToAdd

myDate = Num2Date(interDateNum, "YYYY-MMM-DD")

form1.DateTimeField2 = myDate



SekharN

www.lawson.com

Avatar

Former Community Member
Actually, I see a gap between javascript Date object and xfa date field. You can't use date field rawValue to create a javascript Date object. date field's rawValue give you canonical date value in format YYYY-MM-DD. javascript Date object can be initialized in this way:

x = new Date ( "January 6, 1972" ).

To use the date field value to build a date string which javascript Date object can accept. You can either write a script function(you may not like to do) or use formattedValue property. To take the second option, you need to set the display format pattern to be MMMM D, YYYY for the input date field. Following script shows how to use formattedValue to create Date object.



var vdate = new Date(input.formattedValue);

var vMonth = vdate.getMonth();

vdate.setMonth(vMonth+1);

var sAdjustDate = vdate.toDateString();

output.formattedValue = sAdjustDate;



The attachment sample shows the same thing.



Henry