Convert from date to int

Highlighted
Five Stars

Convert from date to int

Is there any way to implement this SQL method to convert date to int in Talend Open Studio?

convert(int, convert(varchar(10), mydate, 112)) 


Accepted Solutions
Eight Stars

Re: Convert from date to int

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date d = sdf.parse("2018-12-19");
sdf.applyPattern("yyyyMMdd");
String newDateString = sdf.format(d);   //20181219

Use SimpleDateFormat parse/format depending on input/output data type (i.e. String or Date)


All Replies
Eight Stars

Re: Convert from date to int

Can you give an example of input(s) and expected output(s)

Five Stars

Re: Convert from date to int

Input : 2018-12-19

Expected output : 20181219

Eight Stars

Re: Convert from date to int

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date d = sdf.parse("2018-12-19");
sdf.applyPattern("yyyyMMdd");
String newDateString = sdf.format(d);   //20181219

Use SimpleDateFormat parse/format depending on input/output data type (i.e. String or Date)

Five Stars

Re: Convert from date to int

where should i write this code

can i convert the ouput to "int" type?

Eight Stars

Re: Convert from date to int

Depends on the requirements, if you're parsing row by row, pass the  input to a tJavaRow and put that code in making sure to pass the row value in and then out. 

You can use Integer.parseInt() to convert string to int.

Five Stars

Re: Convert from date to int

Thank you soo much Smiley Happy 

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 3

Read about some useful Context Variable ideas

Blog