[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More


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,922 Points
1 Endorsement
Last Modified:
Didier Vally
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 :

Open in new window

This can be split visually to understand more clearly :

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!

Featured Post

Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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