Pages

Monday, May 21, 2012

Important date functions in Oracle BPEL


Important date functions in Oracle BPEL:

Format-dateTime:

This function returns the formatted string of dateTime using the format provided.

xp20:format-dateTime(dateTime as string, format as string)
  •   dateTime – The dateTime to be formatted
  •    format – The format for the output
Format String:-

Format Date Time: Year

Example
Expression
2012
[Y0001]
2012
[Y]
12
[Y01]
Two Thousand and Twelve
[YWw]

Format Date Time: Month

 Example
Expression
08
[M01]
8
[M]
VIII
[MI]
August
[MNn]
AUGUST
[MN]
Aug
[MNn,*-3]
AUG
[MN,*-3]

                                      
Format Date Time: Day

Example
Expression
05
[D01]
5
[D]
5
[D1]
31st
[D1o]
Tuesday
[FNn]


Format Date Time: Hour

Example
Expression
3
[h]
9
[H]
08
[H01]

Format Date Time: Minute
Example
Expression
03
[m01]
3
[m]

Format Date Time: Second
Example
Expression
09
[s01]
9
[s]

Format Date Time: Millisecond
Example
Expression
257
[f001]

Format Date Time: AM/PM
Example
Expression
PM
[PN]
Am
[Pn]

Format Date Time: GMT
Example
Expression
GMT+02:00
[z]


Example:-

xp20:format-dateTime(xp20:current-dateTime(),"[D01]/[M01]/[Y0001] [H01]:[m01]:[s01]")

add-dayTimeDuration-from-dateTime:

This function returns a new date time value adding dateTime to the given duration.
If the duration value is negative, then the resulting value precedes dateTime.

xp20:add-dayTimeDuration-from-dateTime(dateTime as string, duration as string)
  • dateTime as string – The dateTime to which the function adds the duration, in string format.
  • duration as string – The duration to add to the dateTime, or subtract if the duration is negative, in string format.
Duration:-

    P1D - a day
    P7D - a week
    P1M - a month
    P1Y1DT1H1S - One year, one day, one hour and one second
    PT5M - five minutes
Example:-

xp20:add-dayTimeDuration-to-dateTime(xp20:current-date(), 'P1D')

subtract-dayTimeDuration-from-dateTime:

This function returns a new dateTime value after subtracting duration from dateTime.
If the duration value is negative, then the resultant dateTime value follows input-dateTime value.

xp20:subtract-dayTimeDuration-from-dateTime(dateTime as string, duration as string)
  • dateTime as string – The dateTime from which the function subtracts the duration, in string format.
  • duration as string – The duration to subtract to the dateTime, or add if the duration is negative, in string format.
Duration:-

    P1D - a day
    P7D - a week
    P1M - a month
    P1Y1DT1H1S - One year, one day, one hour and one second
    PT5M - five minutes

Example:-
xp20:subtract-dayTimeDuration-from-dateTime(xp20:current-date(), 'P1D')







14 comments:

  1. HI,
    I want to convert date '01-MAY-2012' to YYYYY-MM-DD format. i used the 'xp20:format-dateTime(procplanebo:EffectiveDate,"[Y0001]-[M01]-[D01]")' but its not working giving me blank value. Plz suggest is sumthng i am doing wrong or how to do this conversion

    ReplyDelete
    Replies
    1. HI,

      sorry its 01-MAY-12

      I want to convert date '01-MAY-12' to YYYYY-MM-DD format. i used the 'xp20:format-dateTime(procplanebo:EffectiveDate,"[Y0001]-[M01]-[D01]")' but its not working giving me blank value. Plz suggest is sumthng i am doing wrong or how to do this conversion

      Delete
  2. HI,
    I want to convert date '01-MAY-12' to YYYYY-MM-DD format. i used the 'xp20:format-dateTime(procplanebo:EffectiveDate,"[Y0001]-[M01]-[D01]")' but its not working giving me blank value. Plz suggest is sumthng i am doing wrong or how to do this conversion

    ReplyDelete
  3. Appreciation for nice Updates, I found something new and folks can get useful info about BEST INFORMATICA ONLINE TRAINING

    ReplyDelete
  4. Can anyone please help and suggest why the below function is not working?

    xp20:add-dayTimeDuration-to-dateTime(xp20:current-date(), 'P5M30S')

    During runtime the current time is added with only 5 mins but not the 30 seconds.

    Please help and suggest if there is any other way with which we can add mins and seconds.

    Thanks in Advance!

    ReplyDelete
    Replies
    1. Try this

      xp20:add-dayTimeDuration-to-dateTime(xp20:current-dateTime(), 'PT5M30S')



      2014-01-10T02:35:14-08:00




      2014-01-10T02:40:44-08:00



      Regards
      Albin I

      Delete
    2. Hi Albin,

      I have tried the function that you mentioned but its still not working for the seconds.

      5 minutes are added to the current time but not the seconds.

      Is there any problem with this function to work with seconds? Any workaround or suggestions?

      Delete
  5. Thanks for the explanation. Really helpful post as always. :)

    ReplyDelete
  6. Hi,
    If you have time included, so the format start with PT, For example to subtrct 2 hours

    xp20:subtract-dayTimeDuration-from-dateTime(xp20:current-dateTime() , 'PT2H')

    cheers
    Khaleel

    ReplyDelete
  7. Thank you for this!!!!

    ReplyDelete
  8. I am trying to find difference of two dates in days in bpel. example date1=2016-12-03T17:05:01.853 and date2=2015-12-03T17:05:01.853, I want to find the difference of date1-date2 output as days. pls help

    ReplyDelete
  9. How can i convert date format from DD-MMM-YYYY format to 2014-01-10T02:35:14-08:00 format

    ReplyDelete