How to calculate Date Duration using XSL Transformation in Oracle BPEL
I had a requirement in Oracle Bpel, that subtracts two dates and convert the Duration in weeks then update in a database field through Webservice, so here below is my requirement.
DURATION in Days = (Date1 – Date2)
Duration in Week = (DURATION in Days) / 7
Achieving the above duration in Java is easy. In Oracle BPEL, we need to handle XML and XSLT most of the time. Initially It took some time to calculate this duration but found this link everything works easy. Ok, here below is the calculation
The below XSLT function calculate duration between two dates and return the result in Weeks
Formula:
Example:
$Date1 = 1 Jan 2017
$Date2 = 31 Feb 2017
O/P => 8 (in Weeks)
The below XSLT function calculate duration between two dates and return the result in Weeks in Decimal
Total Duration
Duration in Days (Result in Decimal)
Duration in Weeks (Result in Weeks)
Example:
Date1 = 1 Jan 2017 8AM
Date 2 31 Feb 2017 5pM
DurationInDays = 58.37 (58 days 9 hours )
Duration in Weeks = 8.33 ( 8 weeks if using Round function )
This post first appeared on Oracle ADF, BPM, BI And Primavera P6 Tutorials, please read the originial post: here