Four Stars

How to keep same date format as Database date format?

How do you keep the same date format coming from mssqlinput?  

Sqlserver date is 2018-06-14 11:44:40.320

When mssqlinput passes a date column to tJavaRow the date output is different in the run console.

Result from run console

[statistics] connected
Input Date: Thu Jun 14 11:44:40 CDT 2018

 

Even I tried converting it in tJavaRow and get the same result.

context.run_date = (TalendDate.parseDate("yyyy-MM-dd HH:mm:ssSmiley FrustratedSS",TalendDate.formatDate("yyyy-MM-dd HH:mm:ssSmiley FrustratedSS",row1.InputStart)));

System.out.println("run_date: "+context.run_date);

 

5 REPLIES
Twelve Stars

Re: How to keep same date format as Database date format?

if ti only for println, You do not need double conversion, use just formatDate

context.run_date_print = (TalendDate.parseDate("yyyy-MM-dd HH:mm:ss.SS",TalendDate.formatDate("yyyy-MM-dd HH:mm:ss.SS",row4.date_as_date))) ;
context.run_date_print_string = TalendDate.formatDate("yyyy-MM-dd HH:mm:ss.SS",row4.date_as_date) ;

System.out.println("run_date_as_date: "+context.run_date_print);
System.out.println("run_date_as_string: "+context.run_date_print_string);

 

run_date_as_date: Thu Jun 14 11:44:40 NZST 2018
run_date_as_string: 2018-06-14 11:44:40.320
-----------
Four Stars

Re: How to keep same date format as Database date format?

Thanks this worked.

 

 

 

Fifteen Stars

Re: How to keep same date format as Database date format?

I think a bigger issue needs tackling here. Dates are NOT stored with formats. They are simply numbers. Your Date format is just how your device makes it human readable to you. When you want to write a date to a String or use a date in a SQL query, you will have to format it because it is being converted to a different class. But if you are simply passing a date as a date class, formats are irrelevant.

Rilhia Solutions
Twelve Stars

Re: How to keep same date format as Database date format?

I think - this is not a "issue", this is just proper usage

-----------
Fifteen Stars

Re: How to keep same date format as Database date format?

I think you may have misunderstood what I was getting at @vapukov. The "issue" here is that too many developers seem confused by Dates and expect them to be formatted as part of the object. This misunderstanding leads to lots of questions and confusion over Dates with Talend.

Rilhia Solutions