Article

coolguys's picture
article
Reads:

4124

Score:
0
0
 
Comments:

1

Adding a Future Date to an UserApp Date Field

Author Info

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

(View Disclaimer)

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 :)


Disclaimer: As with everything else at Cool Solutions, this content is definitely not supported by Novell (so don't even think of calling Support if you try something and it blows up).

It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.




User Comments

rkalfane's picture

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

© 2013 Novell