cancel
Showing results for 
Search instead for 
Did you mean: 

Date validation

Former Member
0 Kudos

Hi

In one of my scenario i have to validate the date ....

From the source i am getting date. i need to validate the date is correct or not means i need check the month and day

My source date format yyyymmdd..

i need to check dd according to month and month value should not be grater than 12.. By using UDF i achive that

venkat

Accepted Solutions (1)

Accepted Solutions (1)

former_member214364
Active Contributor
0 Kudos

Hi Venkat,

Here is simple UDF code for validating Date

your source date format must be <b>DD/MM/YYYY</b>(Just use standard Date transformation function)

create value UDF with following code

Note: <b>a</b> is your input date

{

String DatePattern = "(?:(31)(
D)(0?[13578]|1[02])
2|(29|30)(
D)(0?[13-9]|1[0-2])
5|(0?[1-9]|1
d|2[0-8])(
D)(0?[1-9]|1[0-2])
8)((?:1[6-9]|[2-9]
d)?
d{2})$|
(29)(
D)(0?2)
12((?:1[6-9]|[2-9]
d)?(?:0[48]|[2468][048]|[13579][26])|(?:16|[2468][048]|[3579][26])00)$";

if(a.matches(DatePattern) )

return "Valid";

else

return "Invalid";

}

Cheers,

Jag

Former Member
0 Kudos

Hi Jag

My source date format is YYYYMMDD

venkat

former_member214364
Active Contributor
0 Kudos

Hi Venkat,

Just use date fromat(<b>DateTrans</b> function) to change from YYYYMMDD to DD/MM/YYYY.

cheers,

Jag

Former Member
0 Kudos

Hi Jag

Once i change date format then i can write the UDF for checking the Date...is that right..

I didnt understand the string part how it works could u explain me ..

venkat

former_member214364
Active Contributor
0 Kudos

Hi Venkat,

> Once i change date format then i can write the UDF

> for checking the Date...is that right..

<b>Yes</b>

> I didnt understand the string part how it works could

its regular expression with valid date,Month and years in java language.

Cheers,

Jag

Former Member
0 Kudos

Thanks Jag

i will try that...

In my scenario even i have to check the whether the header record is there or not if not then i have to raise an exception..

By using UDF how we check whether Header record exists or not

venkat

former_member214364
Active Contributor
0 Kudos

Hi Venkat,

if you want to check <b>Header</b> Node existance just use <b>exists</b> Node function.

<b>exists</b> function returns true if <b>Header</b> Node exists otherwise false.

if its <b>false</b> call UDF to raise an exception(Go through the following weblog to raise an exception)

/people/alessandro.guarneri/blog/2006/01/26/throwing-smart-exceptions-in-xi-graphical-mapping

Cheers,

Jag

Former Member
0 Kudos

Hi Jag

I am trying to do date function but i am getting error

RuntimeException in Message-Mapping transformation: Runtime exception during processing target field mapping /ns0:MT_TaxBalances/MessagePayload/Record/EndDate. The message is: Unparseable date: ""

venkat

Former Member
0 Kudos

Hi Venkat,

Pass the input value for you date function in a correct format (source format).

i.e yyyyMMdd, otherwise date trans function will error out.

Regards

Anand

Former Member
0 Kudos

Hi Jag

As i am new for writing UDF function can provide me the code for checking the Header record

venkat

Former Member
0 Kudos

Thanks Jag

I solve the date Validation ...only thing i need to do the header validation

Plz Help me Jag

venkat

Answers (2)

Answers (2)

justin_santhanam
Active Contributor
0 Kudos

Venkatesh,

Refer my thread : and check for my reply.

Best regards,

raj.

former_member214364
Active Contributor
0 Kudos

Hi venkat,

To achieve your requirement, you have to go for UDF.

i will let you know the code to do this validation.

Cheers,

Jag