How to keep same date format as Database date format?

Six 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);

 

Forteen 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
-----------
Six Stars

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

Thanks this worked.

 

 

 

Community Manager

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.

Forteen Stars

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

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

-----------
Community Manager

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.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog