Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
ManojKD
Contributor
Contributor

Convert string to Date , throws unparseable error

Hi All,

 

I have a requirement to convert a string of type "20190101" getting in a file which has to be converted to date of format "2019-01-01" (YYYY-MM-DD). I tried using  TalendDate. Parsedate("YYYY-MM-DD","row1.col1") , TalendDate.ParsedateLocale("YYYY-MM-DD","row1.col1","EN") but nothing works for me, getting compilation error during test and got unparseable date error during execution. I have attached the screenshot for reference.

 

Anybody help me on this, Thanks in advance.

Labels (3)
1 Solution

Accepted Solutions
manodwhb
Champion II
Champion II

@ManojKD , You can try the below way.

 

0683p000009M8b2.png0683p000009M8b7.png

View solution in original post

7 Replies
Anonymous
Not applicable

Hi
If the input data is "20190101", try this to convert the string data to a Date
TalendDate.parseDate("yyyyMMdd", row.col1)
If you want to change it to a string with another format, use this expression:
TalendDate.formatDate("yyyy-MM-dd", TalendDate.parseDate("yyyyMMdd", row.col1))

Hope it helps!

Regards
Shong
manodwhb
Champion II
Champion II

@ManojKD , You can try the below way.

 

0683p000009M8b2.png0683p000009M8b7.png

ManojKD
Contributor
Contributor
Author

Hi Shong,

 

Thanks for your quick support, I have tried with your methodology, but still getting error message as "cannot convert string to date".

 

0683p000009M8VZ.png

Is this related to JVM compatibility? If yes please help me to resolve this. I have mentioned the log details below, .

org.talend.designer.runprocess.ProcessorException: Job compile errors
At least job "AD_BK" has a compile errors, please fix and export again.
Error Line: 1148
Detail Message: Type mismatch: cannot convert from String to Date
There may be some other errors caused by JVM compatibility. Make sure your JVM setup is similar to the studio.

 at org.talend.designer.runprocess.JobErrorsChecker.checkLastGenerationHasCompilationError(JobErrorsChecker.java:326)

 at org.talend.designer.runprocess.DefaultRunProcessService.checkLastGenerationHasCompilationError(DefaultRunProcessService.java:380)

 at org.talend.designer.runprocess.RunProcessService.checkLastGenerationHasCompilationError(RunProcessService.java:292)

 at org.talend.designer.runprocess.ProcessorUtilities.generateBuildInfo(ProcessorUtilities.java:634)

 at org.talend.designer.runprocess.ProcessorUtilities.generateCode(ProcessorUtilities.java:523)

 at org.talend.designer.runprocess.ProcessorUtilities.generateCode(ProcessorUtilities.java:1413)

 at org.talend.designer.runprocess.RunProcessContext$1.run(RunProcessContext.java:576)

 at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:466)

 at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:374)

 at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:527)

 at org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog.run(ProgressMonitorJobsDialog.java:284)

 at org.eclipse.ui.internal.progress.ProgressManager.run(ProgressManager.java:1190)

 at org.talend.designer.runprocess.RunProcessContext.exec(RunProcessContext.java:531)

 at org.talend.designer.runprocess.ui.ProcessComposite.exec(ProcessComposite.java:1450)

 at org.talend.designer.runprocess.ui.views.ProcessView$RunAction.run(ProcessView.java:691)

 at org.talend.designer.runprocess.ui.actions.RunProcessAction.run(RunProcessAction.java:58)

 at org.talend.designer.core.debug.JobLaunchConfigurationDelegate$1.run(JobLaunchConfigurationDelegate.java:84)

 at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)

 at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:136)

 at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4147)

 at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3764)

 at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)

 at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)

 at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)

 at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)

 at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)

 at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)

 at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)

 at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)

 at org.talend.rcp.intro.Application.start(Application.java:255)

 at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)

 at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)

 at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)

 at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)

 at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)

 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

 at java.lang.reflect.Method.invoke(Unknown Source)

 at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)

 at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)

 at org.eclipse.equinox.launcher.Main.run(Main.java:1465)

 

ManojKD
Contributor
Contributor
Author

Hi Manohar,

 

Thank you so much , Its working!!. I tried converting an invalid date  "20200231"  expectation is to get an error message as invalid date, but Talend converts into "2020-02-31".  Can you please look into this and guide me with your inputs.

0683p000009M7kg.png

 

 

 

 

 

manodwhb
Champion II
Champion II

@ManojKD , are you sure about your data ? are you getting data like 20190101 ,if yes below expression and my other solution should work.  if you still see an error then should be null or space or some other format may be you have in your data, you need to check the data.

 

 you need to add below way for @shong solution.

TalendDate.parseDate("yyyy-MM-DD",TalendDate.formatDate("yyyy-MM-DD",TalendDate.parseDate("yyyyMMdd",row6.sting_date)))

 

ManojKD
Contributor
Contributor
Author

Hi Manohar,

Your previous solution worked for me after making a small change in the target schema , I have modified the date format from "YYYY-MM-DD" to "yyyy-mm-dd".
manodwhb
Champion II
Champion II

great @ManojKD