Posts

Showing posts from August, 2015

OSB 12c Xquery function to convert the date of credit card expiry date to yyyy-MM-dd

I had a requirement to convert the credit card expiration date in the form of “201506” to “yyyy-MM-dd”. The challenge here is adding the day value, we have to add the last day of the respective month. For example, if we get 201502, the converted date should be “2015-02-28” Here is the function to convert this date format. Xquery: xquery version "1.0" encoding "utf-8"; (:: OracleAnnotationVersion "1.0" ::) declare namespace functx = "http://www.functx.com"; declare variable $inputDate as xs:string external; declare function functx:days-in-month   ( $date as xs:anyAtomicType? )  as xs:integer? {    if (month-from-date(xs:date($date)) = 2 and        functx:is-leap-year($date))    then 29    else    (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)     [month-from-date(xs:date($date))] } ; declare function functx:is-leap-year   ( $date as xs:anyAtomicType? )  as xs:boolean {            for $year in xs:integer(subs