Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
i need help with converting the Date-Part of tFileInputMail into a real date and time to store this in an Oracle table. The Date-Part comes out like
"Fri, 30 Sep 2022 09:44:25 +0000"
or
"Thu, 27 Oct 2022 13:26:47 +0000"
sometime the have additinal timezine information like
"Wed, 10 Aug 2022 16:25:13 +0200 (CEST)"
How can i get those date-parts to e.g. "2022-09-30 09:44:25" or in general to "yyyy-MM-dd HH:mm:ss" so that i can store them into a database table?
Kind regards
OK, the best way to do this is probably to build a routine for this. A routine is a simple Java class. First of all make sure you nail your requirements. Try out a few dates with this code below.....
***************************************************************************************
String date1 = "Thu, 27 Oct 2022 13:26:47 +0000";
String date2 ="Wed, 10 Aug 2022 16:25:13 +0200 (CEST)";
String date = date2;
if(date.contains("(")){
date = date.substring(0,date.indexOf('(')-1);
}
Date myDate = routines.TalendDate.parseDate("E','dd MMM yyyy HH:mm:ss Z", date);
System.out.println(routines.TalendDate.formatDate("yyyy-MM-dd HH:mm:ss", myDate));
***************************************************************************************
I quickly knocked this up to demonstrate. If you add this to a tJava and try out different hardcoded date Strings, you can tweak as necessary. All the above is doing is either taking the "date1" or "date2" and setting it to the "date" variable and then running the rest of the code.
Putting this into a tJava, i get:
Exception in component tJava_1 (Date_Test)
java.lang.RuntimeException: java.text.ParseException: Unparseable date: "Thu, 27 Oct 2022 13:26:47 +0000"
at routines.TalendDate.parseDate(TalendDate.java:971)
at routines.TalendDate.parseDate(TalendDate.java:915)
at test.date_test_0_1.Date_Test.tJava_1Process(Date_Test.java:349)
at test.date_test_0_1.Date_Test.runJobInTOS(Date_Test.java:642)
at test.date_test_0_1.Date_Test.main(Date_Test.java:480)
Caused by: java.text.ParseException: Unparseable date: "Thu, 27 Oct 2022 13:26:47 +0000"
at java.base/java.text.DateFormat.parse(DateFormat.java:399)
at routines.TalendDate.parseDate(TalendDate.java:957)
This error comes from
Date myDate = routines.TalendDate.parseDate("E','dd MMM yyyy HH:mm:ss Z", date);
Could it be, that i need to tell the converter that the date isn't in my local notation (german), because of the Weekday (Thu)?
Kind regards