cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
482
Views
3
Helpful
6
Replies

CRS 3.5 Add 14 days to todays date

dagraham
Level 1
Level 1

I have a CRS 3.5 installation, We have a need to add 14 days to a date. I am having trouble getting CRS to do this.

Any help would be very helpful.

6 Replies 6

BCOLE2007
Level 1
Level 1

Hi dagraham

couple options I have ideas for.

Option A: Using CRS completely

1) Use the .month method to extract the Month from the date in a Set statement

2) Use the .dom method to extract the day of the month form the date in another set statement

2.5) Use the .year method to extract the year from the date in another set statement.

3) Add 14 days to the step 2 Day variable

4) Now the fun, You need to logical step statement, such as a switch or nested if, then looks up the month from step 1 and checks to see if the days from step 3 is over the number of days for the month, if it is subtract the number of days from the month, to get the day for the next month and add 1 to the next month

5) Remember the date exceptions, such as the Febuary leap year check, and if 14 days are added in the last 2 weeks of december then you would also need to set the Month to 1 for Jan(don't add it) and bump the year by one.

6) Build a new date variable using the calculated Day, Month and Year

This can be coded entirely in 1 set statement using Java or in a custom class.

Option B:

1) Use a database, select the date +14 from a dummy table

for example in oracle:

ensure $yourDate is in the format of the to_date string

Select

to_char(to_date($yourDate,'MM/DD/YYYY')+14) as Date2weeks from dual

SQL server and DB2 should be able to do a similar kind of select as well

2)

Use a Work Record in your Get Step with a field

called Date2weeks defined in it.

this works in CRS 4.1 with Oracle 10g

Blair

*Please rate useful posts

The Calendar class in Java will take care of all of your month and year overflows, dealing with leap years. My God, it was developed for this very reason.

Regards,

Geoff

Sweet, another idea, haven't worked with it though.

I don't see anything in the 4.1 docs for the calender class but see the type in the editor.

Blair

dagraham
Level 1
Level 1

Thanks for the replies. I would have loved to use ths calendar class and the add method but do not know java well enough.

We solved it this way.

1. Created an execute java method to get the current date in milliseconds. Used java.lang.System variable type and currentTimeMillis() method.

2. Used a set to add the result from the last step + the number of milliseconds for 14 days.

3. Created a new java object date type using the constructor date(long) so we have it saved as a date and not in milliseconds(long variable type).

We tested this for year end and leap year and it works great.

Sounds like a 4th way

Glad you found a way to do it.

Good Job!

Blair

>I would have loved to use ths calendar class and the add method but do not know java well enough

FYI - sample code ....

import java.util.Date;

import java.util.Calendar;

import java.util.GregorianCalendar;

public class TCal

{

public TCal()

{

super();

}

private void doIt()

{

Calendar today = new GregorianCalendar();

today.add(Calendar.DATE, 14);

Date theDate = today.getTime();

System.out.println(theDate.toString());

}

public static void main(String[] args)

{

TCal tr = new TCal();

tr.doIt();

}

}

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: