SQL Server Date time to Salesforce Date in Mule - java

I have a SQL Server Datetime field with value 1962-04-04 00:00:00.0. This needs to be pushed into Salesforce date field through Mule. I am handling this conversion in the data mapper.
I have tried many possibilities but nothing works. Any pointers would help.
The last one I tried was as below. I thought it should work.
output.PersonBirthdate1 = str2date(input.DATE_OF_BIRTH, "yyyy-MM-dd hh:mm:ss.ZZZ");
But it gives an error:
Caused by: [Error: java.text.ParseException: Unparseable date: "1962-04-04 00:00:00.0"]

Bases on the format of the date,it would be:
str2date(input.DATE_OF_BIRTH,"yyyy-MM-dd HH:mm:ss.S")

Related

H2 DB - Strange problem with PARSEDATETIME on different systems

I'm trying to parse a timestamp in an H2 DB with format 4/24/2022 6:03:30 pm using PARSEDATETIME.
PARSEDATETIME(created, 'M/d/yyyy h:mm:ss a')
It works like a charm on my computer.
However, if it is run on the computer of a client, it results in the following error message:
org.h2.jdbc.JdbcSQLDataException: Error parsing "4/24/2022 6:03:30 pm";
Caused by: java.time.format.DateTimeParseException: Text '4/24/2022 6:03:30 pm' could not be parsed at index 18
Any ideas what causes this problem - and more importantly, any suggestions how to solve this? Thanks in advance!
PARSEDATETIME(created, 'M/d/yyyy h:mm:ss a', 'en')
AM/PM are English (okay Latin) abbreviations. So add the locale 'en' as parameter.

How to parse string to date format in java

I have a file file_20201013_012417.txt and I want to validate the timestamp 20201013_012417 format of this file is YYYYMMDD_HHmmSS.
I have tried SimpleDateFormat , but getting java.text.ParseException: Unparseable date execption.
Any help is appreciated.
As I known, you can try to edit the concurrency number for your pipeline at the last step of creating.
Please see the figure below.

Spring Batch - unable to parse date with correct format

In spring batch I'm loading csv file where I'm also parsing dates.
Everything seems to be working fine except for one single row where I get exception
Unparseable date: "2014-03-09 02:07:07", format: [yyyy-MM-dd HH:mm:ss]
I've double checked my input file and there are no special/invisible characters in this failed row.
Caused by: java.lang.IllegalArgumentException: Unparseable date: "2014-03-09 02:07:07", format: [yyyy-MM-dd HH:mm:ss]
at org.springframework.batch.item.file.transform.DefaultFieldSet.parseDate(DefaultFieldSet.java:778)
at org.springframework.batch.item.file.transform.DefaultFieldSet.readDate(DefaultFieldSet.java:595)
Thanks for help!
EDIT
When I change hour in date from 02 to something else (e.g. '2014-03-09 03:07:07'), it works. When I then change it manually back to 02 it fails again. How can this be possible? Changing other elements of date does not help. Only changing hour.
I only experience this on our unix server with America/New_York timezone. From my local machine everything is working. JDK version on both are identical.
It was caused by combination of TimeZone settings, daylight saving and SimpleDateFormat.lenient property.
Our linux host has America/New_York timezone.
Date for which I was getting error is 9-MAR-2014 # 2:07:07 am
which is exact date and time when in NYK timezone time shifts 1 hour forward - daylight saving (from 2am to 3am).
Normally when SimpleDateFormat converts such date it automatically changes it to 3am. Setting lenient property to false (default value for is true) prevents this and throws exception - HOUR_OF_DAY: 2 -> 3.
This exception is consumed in process and at the end we get only IllegalArgumentException with Unparseable date: "2014-03-09 02:07:07", format: [yyyy-MM-dd HH:mm:ss] message.
Here I'm using spring-boot DefaultFieldSet which has implementation where it is specifically setting lenient to false.
/* ... some other code ... */
private DateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
{
dateFormat.setLenient(false);
}
/* ... some other code ... */
#Override
public Date readDate(int index, String pattern) {
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
sdf.setLenient(false);
return parseDate(readAndTrim(index), sdf);
}
/* ... some other code ... */
As we are not doing any manipulation with dates in our code, I simply fixed it with changing default timezone to UTC.
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
Other valid approach would be to write custom implementation of FieldSet.

How to display date in grails which we got from running SQL statement using groovy?

I am getting an exception when I try to format the date which is in oracle.sql.TIMESTAMP. How can format this?
When I try to retrieve the date from the database, I am using the groovy to get the data:
Groovy doc but it doesn't have anything particular to date
// Part of the code
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss:SSS")
def sql = new Sql(dataSource)
sql.eachRow('''select dateCreated from User'''){
row->
def dateCreated
if(row.dateCreated != null){ // I am getting the object as oracle.sql.TIMESTAMP.
dateCreated= df.format(row.dateCreated)
}
}
I am getting the exception like this .
2015-11-05 14:22:33,755 [http-8083-3] ERROR errors.GrailsExceptionResolver - Exception occurred when processing request: [GET] /getUsers - parameters: _dc: 1446713474579
Stacktrace follows:
java.lang.IllegalArgumentException: Cannot format given Object as a Date
at java.text.DateFormat.format(DateFormat.java:281)
at java.text.Format.format(Format.java:140)
at java_text_Format$format.call(Unknown Source)
at com.test.AdminController$_closure15_closure80.doCall(AdminController.groovy:953)
at $Proxy76.eachRow(Unknown Source)
at com.test.AdminController$_closure15.doCall(AdminController.groovy:941)
at com.test.AdminController$_closure15.doCall(AdminController.groovy)
at com.test.SecureController.invokeMethod(SecureController.groovy)
at com.test.AdminController$_closure21.doCall(AdminController.groovy:1061)
at com.test.AdminController$_closure21.doCall(AdminController.groovy)
at org.grails.jaxrs.web.JaxrsFilter.doFilterInternal(JaxrsFilter.java:46)
at java.lang.Thread.run(Thread.java:662)
If it is oracle.sql.TIMESTAMP you are talking about, take a look here http://docs.oracle.com/cd/E18283_01/appdev.112/e13995/oracle/sql/TIMESTAMP.html
This class has a lot of usefull methods to convert it to java.sql.Date (dateValue()) or java.sql.Timestamp (timestampValue()) etc.
Once you get to those it's pretty easy to convert them to java.util.Date. For example take a loo here How to convert from java.sql.Timestamp to java.util.Date?
Cannot format given Object as a Date , this error clearly indicates that first you need to typecast the result you are getting to date and then format it.
Date date = Date.parse("yyyy/MM/dd HH:mm:ss",row.dateCreated)
This should work.

Unparseable date with SimpleXml

I am using Simple XML for XML serialization in my Android project. I have problem with parsing a Date object. I receive an exception:
Unparseable date: 2012-05-01T08:22:34+02:00
Can anyone help me how to tell Simple XML what the date format is? Thanks.
SimpleXML only supports some DateFormat's, but you can use a custom Transform for Dates.
Try my example i posted here: Parse date with SimpleFramework
You have a timezone at the end of your date. Java can parse timezone offsets, but without the ยด:' divider between. So if your date timezone were +0200 instead of +02:00, it should work. You could run it through a SimpleDateFormatter.

Categories