Date formatting

Highlighted
Four Stars

Date formatting

Hi Everyone,

 

I'm trying to extract the data from Drupal using Talend and i'm having troubles with formatting the String date in Drupal to the Date format.

 

Source Date: Thu Aug 18 00:00:00 BST 2016 (Type String)

Target Date:  2016-08-18T00:00:00.000Z (Type Date)

 

I've tried various expressions in Talend.Date() method but couldn't figure it out yet. Do you guys have any idea about this?

 

Thanks,

 

Regards,

Hasitha


Accepted Solutions
Highlighted
Four Stars

Re: Date formatting

Thanks for the quick response rhall. I think i've got to a point that i can work it out.

View solution in original post

Highlighted
Community Manager

Re: Date formatting

Hi @hasitha, you need to accept the post which gave you the solution. Otherwise people also suffering with the same issue will not find it easily. Thanks.

View solution in original post


All Replies
Highlighted
Community Manager

Re: Date formatting

First of all, you should be aware that the Date class stores dates as numbers. Format is irrelevant here. So you just want to convert to a Date from String. Having said that, I have included code to convert back to a String in the format you want. The code is below...

 

String date = "Thu Aug 18 00:00:00 BST 2016"; //Set your example date
Date myDate = routines.TalendDate.parseDate("EEE MMM dd HH:mm:ss z yyyy", date); //Convert the example date to a Date

//Print the Date object to a String in the format you specified
System.out.println(routines.TalendDate.formatDateLocale("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", myDate, "BST"));
Highlighted
Four Stars

Re: Date formatting

Thanks for the quick response rhall. I think i've got to a point that i can work it out.

View solution in original post

Highlighted
Community Manager

Re: Date formatting

Hi @hasitha, you need to accept the post which gave you the solution. Otherwise people also suffering with the same issue will not find it easily. Thanks.

View solution in original post

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

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

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