Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

how do I display today's date and a date 1 month from today in livecycle designer

Avatar

Avatar
Validate 1
Level 1
Peter_Miles
Level 1

Like

1 like

Total Posts

10 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
Peter_Miles
Level 1

Like

1 like

Total Posts

10 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
Peter_Miles
Level 1

30-06-2009

Hello,

Does anyone know how to display a future dates in 3 date fields that would be 1 month; 2 months and 3 months from today?

I am making a sales contract form and in a date field is today's date (which can be altered if the user needs to change it).  The javascript I have is:

if

(this.rawValue == null

){

var

msNow = (new

Date()).getTime();

var

d1 = new

Date(msNow);

this.rawValue

= util.printd("mmm/dd/yyyy",

d1);

}

else

{

this.rawValue

= rawValue;

}

Then in the next date field i need to display the date 1 month from today

The third date field 2 months from today

the fourth date filed 3 months from today.

Any suggestions would be greatly appreciated.

Accepted Solutions (0)

Answers (7)

Answers (7)

Avatar

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

270 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

270 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile
_Bruce_Robertson
MVP

01-07-2009

Hi Peter,

If you need to be more exact than adding 30 days then you can use the following code;

function

addMonth(date)

{

  var year = date.getFullYear();

  var month = date.getMonth();

  var day = date.getDate();

  month

= (month % 12) + 1;

  year

+= parseInt(month / 12);

  var days = daysInMonth(month, year);

  if (day > days)

  {

    day

= days;

  }

  return new Date(year, month, day);

}

function

daysInMonth(iMonth, iYear)

{

  return 32 - new Date(iYear, iMonth, 32).getDate();

}

You need to pass in a Date object to addMonth so (assuming DateTimeField1 is your date field);

NextMonth.rawValue

= util.printd("mmm/dd/yyyy", addMonth(

= util.printd("mmm/dd/yyyy", addMonth(

Date.parse(DateTimeField1.formattedValue));

Bruce

Avatar

Avatar
Validate 1
Level 1
Peter_Miles
Level 1

Like

1 like

Total Posts

10 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
Peter_Miles
Level 1

Like

1 like

Total Posts

10 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
Peter_Miles
Level 1

06-07-2009

Bruce you are Brilliant!!

Thanks very much for all your help

Avatar

Avatar
Validate 1
Level 1
Peter_Miles
Level 1

Like

1 like

Total Posts

10 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
Peter_Miles
Level 1

Like

1 like

Total Posts

10 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
Peter_Miles
Level 1

06-07-2009

Hi Bruce,

Thanks very much for you last post on July 3rd. I notice that the attachment on the Forum is still marked as "Queued" and I was wondering if it would be possible for you to email it to me directly?

Thanks,

Peter

pmiles@cloverdalepaint.com

Avatar

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

270 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

270 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile
_Bruce_Robertson
MVP

03-07-2009

Hi Peter,

I've updated your form, I moved the code into a script object so it can be called from the calculate event of the three date fields.

I made the date fields "calculate - read only", the base date field is "calculate - user can override" so the user gets a warning message, you could remove this by making it "user entered - optional".

I changed the addMonths function so it takes a number of months, so it works 1, 2 or 3 months from the base date not one month following the previous calculated date. Which looking at your form I assume is what you would want, not one month following the previously calculated date.

There seemed to be a cut and paste error in my previous reply which would have caused your problems ... sorry.

Bruce

Avatar

Avatar
Validate 1
Level 1
Peter_Miles
Level 1

Like

1 like

Total Posts

10 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
Peter_Miles
Level 1

Like

1 like

Total Posts

10 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
Peter_Miles
Level 1

02-07-2009

Hi Bruce,

Thanks, I do need it to be more exact and as I am a newbie to javascript I think I am having trouble assigning the correct "addmonth".  Maybe the synatx I put is incorrect or perhaps I have put the code into the wrong datetime field.  I have attached the file so you can see what I have done.  Could you please have a look??

thanks very much,

Peter

Avatar

Avatar
Level 1
usualo0
Level 1

Likes

0 likes

Total Posts

4 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
usualo0
Level 1

Likes

0 likes

Total Posts

4 posts

Correct Reply

0 solutions
View profile
usualo0
Level 1

02-07-2009

I had a similar question a few weeks back and I found a post that I took code from that seemed to work for me. You can modify it however you like, I don't remember how the original code was, I think they had it set up to calculate exactly one year from the date entered.

I modified it to add an input number of months (numberMonths)  to the date entered when data is merged with the form (dateField1). This is my code. (I put it on validate event)

if (this.rawValue != null ){

// convert date string to a date time object

var oDate = util.scand("mm/dd/yyyy", page1.dateField1.formattedValue);

// extract the full Year

var sFullYear = oDate.getFullYear();

// extract zero based month

var sMonth = oDate.getMonth();

// extract date

var sDate = oDate.getDate();

// create formatted display string from month, date, and  year plus x amount of months

dateField2.formattedvalue = util.printd("mm/dd/yyyy", new Date(sFullYear, (sMonth + numberMonths.rawValue), sDate));

page1.dateField2.rawValue = dateField2.formattedvalue;

}

I hope this helps!

Avatar

Avatar
Validate 1
Level 4
Paul_Butenko
Level 4

Likes

23 likes

Total Posts

234 posts

Correct Reply

27 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile

Avatar
Validate 1
Level 4
Paul_Butenko
Level 4

Likes

23 likes

Total Posts

234 posts

Correct Reply

27 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 10
Boost 1
View profile
Paul_Butenko
Level 4

30-06-2009

Hi,

I made example form for you. Date() returns current system date as the number of days since the epoch. You can add 30 days and it will be one month fron now.

BR,

Paul Butenko