cancel
Showing results for 
Search instead for 
Did you mean: 

Calculating num of days between two date

Former Member
0 Kudos

Hi friends,

I have to find difference between two dates. I am not using any SQL tables.I getting the date from a bapi . so cud anyone tell me how to calculate the no of days between two dates.

regards,

M.Arunkumar

Accepted Solutions (0)

Answers (3)

Answers (3)

nitin_mahajan2
Contributor
0 Kudos

Just had 2 input fields in page one and also attributes of type date as startDate and EndDate.

another atribute in the Context as Days

attribute days in the second page for display.

Map "Days" in Page 2 with that of Context.

Use the following code in the onSubmit of page One:

long days ;

Date strDate = null ;

Date endDate = null ;

strDate = wdContext.currentContextElement().getStartDate() ;

endDate = wdContext.currentContextElement().getEndDate() ;

days = (strDate.getTime() - endDate.getTime())/(2436001000)+1 ;

wdThis.wdGetFirstPageController().wdGetContext().currentContextElement().setDays( String.valueOf(days) ) ;

Depending on, whether you want to include the last day in the calculation, use / not use the "+1" factor.

nitin_mahajan2
Contributor
0 Kudos

forgot to mention, the type od Days Attribute is String.

Former Member
0 Kudos

Hai,

long strt=fromDate().getTime();

long end=toDate().getTime();

int days=(end-strt)/(10006060*24);

Regards,

Naga

Former Member
0 Kudos

Hi,

For example,u have two attributes BEGINDATE & ENDDATE with date type in component controller...u create other attribute DURATION and in properties set datatype as LONG,calculated= TRUE then it will create two methods,

1)getDuration

2)setDuration

then in implementation getDuration()

return (element.getDATE_END().getTime() -

element.getDATE_BEGIN().getTime())

/ (24 * 3600 * 1000) + 1;