Technical Tip

coolguys's picture

Adding a Future Date to an UserApp Date Field

Author Info

5 March 2008 - 7:35am
Submitted by: coolguys

tip
Reads:

650

Score:
0
0
 
Comments:

1

Problem

A Forum reader recently asked:

"I have question about how to add a future date to a date field. With IE it gives me the correct date for the datepicker field, but when the date value has been saved to eDirectory, it is shown like "Sun Oct 22 07:11:36 EET 1911". And with Firefox it shows an incorrect value in datepicker field - "11/27/-1753" - which cannot be saved in MM/DD/YYYY format."

And here are the responses from Rudy Duym and John DaSilva ...

Solution

Rudy Duym

You could try the following script inside a workflow form event. This will add 3 days to the current date, and it should work on all browsers :

var s = new Date().getTime();
s = s + 3 * 1000 * 24 * 60 * 60;  // add 3 days to today and show that
form.setValues("hireddate", form.dateToString(new Date(s), true));

John DaSilva

To add 10 years, to the current date, try:

expirationdate.setFullYear(expirationdate.getFullYear()+10);
form.setValues(targetfield2, form.dateToString(expirationdate));

In Designer, in the Expression builder, there are tooltips for most of the functions. Let the mouse button hover over the Functions/Methods and you will see a note that getYear and setYear are not recommended, because of Y2K. Man, it has been a while since I had to think about that :)


Author Info

5 March 2008 - 7:35am
Submitted by: coolguys




User Comments

GregorianCalendar can help

Submitted by rkalfane on 5 March 2008 - 10:25am.

Hello!

To manipulate dates like adding, substracting, rolling I would strongly suggest to use the standard GregorianCalendar Java class.

Have a look at the Java documentation here: http://java.sun.com/j2se/1.4.2/docs/api/java/util/GregorianCalendar.html.

I used that to add months to user end dates to automatically disable target accounts / delete accounts / send notififications.

For instance, I used the following either in the DAL, workflows or rules (sorry I don't remember if it is working in all three areas or only for rules):

function addMonths(aDateMillis,aInt)
{
    var oCalendar = new GregorianCalendar();

    oCalendar.setTimeInMillis(aDateMillis*1000);
    oCalendar.add(oCalendar.MONTH,aInt);

    return (oCalendar.getTimeInMillis()/1000); 
}

I am sure you can find a lot of examples searching on Google Code... Used with the SimpleDateFormat class, you can display dates using the format you want...

Cheers,

Reza

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <p> <a> <em> <i> <cite> <code> <img> <ul> <ol> <li> <div> <dl> <dt> <dd> <b> <strong> <h1> <h2> <h3> <pre> <table> <td> <tr> <th> <blockquote>
  • Lines and paragraphs break automatically.
  • Glossary terms will be automatically marked with links to their descriptions. If there are certain phrases or sections of text that should be excluded from glossary marking and linking, use the special markup, [no-glossary] ... [/no-glossary]. Additionally, these HTML elements will not be scanned: a, abbr, acronym, code, pre.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
5 + 15 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

© 2008 Novell, Inc. All Rights Reserved.