<

How to add N days to the current date of day, then format the date according to "dd/mm/yyyy" in BPEL.

Published on
14,697 Points
8,597 Views
1 Endorsement
Last Modified:
Approved
Didier Vx
I have been involved in projects for Renault (GST Project), Orange (COME Project), SFR (P6 Project), Samsung, Poclain Hydraulics, EDF...
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs.

First of all, let's see how to add 1 day to the current date, in a XSL expression:
xp20:add-dayTimeDuration-to-dateTime(xp20:current-date(), 'P1D')

Open in new window


There are 2 functions used here. The most important part in this article is the special format 'P1D' which means "one day". So the current date is obtained with the "xp20:current-date()" and the number of days to add is defined with the '1' between the 'P' and the 'D' in the format 'P1D'.

So to add N days, the format must be in the following form : 'P' + number of days + 'D'. For example, to add 40 days to the current date and to get back the new calculated date, the following command must be used :
xp20:add-dayTimeDuration-to-dateTime(xp20:current-date(), 'P40D')

Open in new window


Now, in an XSL expression referencing a XSL variable in which the number of days is, that would be done with something that looks like that :

<from expression="xp20:add-dayTimeDuration-to-dateTime(xp20:current-date(),concat('P',String(bpws:getVariableData('OnMessage_1_InputVariable','parameters','/ns1:MyParam/ns1:NumberOfDays')),'D'))"/>

Open in new window


Let's take the expression only :
xp20:add-dayTimeDuration-to-dateTime(xp20:current-date(),concat('P',String(bpws:getVariableData('OnMessage_1_InputVariable','parameters','/ns1:MyParam/ns1:NumberOfDays')),'D'))

Open in new window


This can be split visually to understand more clearly :
xp20:add-dayTimeDuration-to-dateTime
(
xp20:current-date(),
concat(
'P',
String(bpws:getVariableData
(
'OnMessage_1_InputVariable','parameters','/ns1:MyParam/ns1:NumberOfDays')
),
'D'
)

Open in new window


The BPEL concatenation function is used and enables to concatenate the 3 parts : the 'P', the number of days and the 'D'.
The String function is used to convert the number of days in character format.
All that can be done with the BPEL Expression Builder when working on a BPEL process. A useful trick is to use CTRL+SPACE to ease the creation of an expression.

Last evolution : Format the result date according to "dd/mm/aaaa" (european countries) :
xp20:format-dateTime(xp20:add-dayTimeDuration-to-dateTime(xp20:current-date(), concat('P',string(bpws:getVariableData('OnMessage_1_InputVariable','parameters','/ns1:MyParam/ns1:NumberOfDays')),'D')),'[D01]/[M01]/[YYYY]')

Open in new window


Here, the format-dateTime function is used, with the specific format '[D01]/[M01]/[YYYY]' that means days with 2 digits, months with 2 digits and year with 4 digits. :)

That's it!
1
Author:Didier Vx
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Get 7 days free