One Star

Date validation

Is there a way to validate the datetime in talend?
is there any method like isValidDate(<<myString as string>>, <<myDateFormat as string>>) return 0 or 1 for OK or Not OK ??
I have feeds that come in with junk data time ---check the month below
In such cases when i format the date to yyyy-MM-dd HH:mm:ss i will get 2008-99-02 15:21:22.. which has invalid month.. and i have to reject the feed and not process it ..
<date year="2008" month="99" date="2" />
<time hour="15" minute="21" second="43" />
Thanks,
Sahana
7 REPLIES
Community Manager

Re: Date validation

Hello Sahana
Try the method isDate(String stringDate, String pattern) provided by Talend. eg:
TalendDate.isDate("2008-99-02 15:21:22", "yyyy-MM-dd HH:mm:ss")

Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Date validation

Shong,
I am trying :-
TalendDate.isDate(keyed_workorders.TARGET_START_DT, "MM/dd/yyyy HH:mm:ss")
where the TARGET_START_DT is defined as a Date type.
I get error Method is undefined for isDate.
Any ideas?
Community Manager

Re: Date validation

Hello guy
where the TARGET_START_DT is defined as a Date type.

The data type of first parameter is String and this method returns a boolean value.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Date validation

Shong,
Whats the best way to convert a date defined field ot a string so that I can use te isdate check?
Also what version of talend was the isdate check valid in?
Community Manager

Re: Date validation

Hello Trevor
Whats the best way to convert a date defined field ot a string so that I can use te isdate check?

To convert a date to a string, you can use method:
TalendDate.formatDateLocale(String pattern, java.util.Date date, String languageOrCountyCode)
The isDate method is be used to check if a date with string format matchs the specify pattern.
Also what version of talend was the isdate check valid in?

I remenbered it is present since TOS3.0
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Date validation

Hello, shong
I am a newbie to Talend, a newbie to Java, and also a newbie who only started working this year...
So I will ask a very very stupid question...
Where do I insert the code? Do I just click 'Advance Mode' in the tFilterRow and type in the code you illustrated above?
(What I need to do is to validate a series of dates, say three columns of date, and ouput them into a comma delimited file if those columns are empty or not a valid date or not in the specified date format.)
Thanks heaps!!
Dragonvoice
Community Manager

Re: Date validation

Hello
Where do I insert the code? Do I just click 'Advance Mode' in the tFilterRow and type in the code you illustrated above?

You can insert the Java code in any text filed, such as 'Advance Mode' in the tFilterRow, the file name filed in tFileInputDelimited, tJava.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business