<

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

Published on
13,530 Points
7,430 Views
1 Endorsement
Last Modified:
Approved
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
Comment
0 Comments

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Join & Write a Comment

Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month