From Thursday, July, 9, 3:00 PM Pacific,
our Community site will be in
read-only mode
through Sunday, July 12th.
Thank you for your patience.

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
Highlighted
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)

View solution in original post


All Replies
Highlighted
Eight Stars

Re: Convert from date to int

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

Highlighted
Five Stars

Re: Convert from date to int

Input : 2018-12-19

Expected output : 20181219

Highlighted
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)

View solution in original post

Highlighted
Five Stars

Re: Convert from date to int

where should i write this code

can i convert the ouput to "int" type?

Highlighted
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.

Highlighted
Five Stars

Re: Convert from date to int

Thank you soo much Smiley Happy 

2019 GARTNER 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

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

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog