cancel
Showing results for 
Search instead for 
Did you mean: 

Finiding no. of days b/w 2 dates

Former Member
0 Kudos

Hi All,

Can find no. of days between 2 dates with simple logic or using any function module?

Thank you,

Prasanna

Accepted Solutions (0)

Answers (3)

Answers (3)

henrique_pinto
Active Contributor
0 Kudos

Some code samples:

Regards,

Henrique.

Former Member
0 Kudos

Hi Prasanna,

Use this function module "DAYS_BETWEEN_TWO_DATES"

Former Member
0 Kudos

Hi Yugapreetha,

Thank You.

Can't do by using any simple code (like Subtract) rather than using Function Module?

Prasanna.

Former Member
0 Kudos

Hi Prasanna,

I think we can't do tat using simple code.

Rgds,

Yuga

Former Member
0 Kudos

Hi,

You can find the difference of two days using simple UDF functions.

import java.util.Calendar;

Create the UDF.

Regards

Sunil.

Here it goes..

import java.util.Calendar;

//write your code here
// Pass the Date format as YYYY.MM.DD. if the inputs format are diffeernt change the substring function accordingly.
String a1 = a.substring(0,4);
String a2 = a.substring(5,7);
String a3 = a.substring(8,10);
String b1 = b.substring(0,4);
String b2 = b.substring(5,7);
String b3 = b.substring(8,10);
//If  you are getting the input as integer it can be direclty passed. Here the UDF is getting the date value as string.
//Convert the String into Int.
int a11 = Integer.parseInt(a1);
int a21 = Integer.parseInt(a2);
int a31 = Integer.parseInt(a3);
int b11 = Integer.parseInt(b1);
int b21 = Integer.parseInt(b2);
int b31 = Integer.parseInt(b3);

Calendar calendar1 = Calendar.getInstance();
Calendar calendar2 = Calendar.getInstance();
//Set the date 
calendar1.set(a11, a21, a31);
calendar2.set(b11, b21, b31);

    long milliseconds1 = calendar1.getTimeInMillis();
    long milliseconds2 = calendar2.getTimeInMillis();
    long diff = milliseconds2 - milliseconds1;
    diff = Math.abs(diff);
    long diffDays = diff / (24 * 60 * 60 * 1000);
    String diff1 = Long.toString(diffDays);
     return diff1;

Edited by: Sunil John on Jan 20, 2009 5:26 PM

prateek
Active Contributor
0 Kudos

Deleted

Edited by: Prateek Raj Srivastava on Jan 20, 2009 9:50 AM