Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
su66
Contributor
Contributor

How to get current date as date datatype in desired date format?

I have tried the below and this is printing Jan 1 2017.

System.out.println(TalendDate.parseDate("MM/DD/YYYY HH:mm:ss", TalendDate.getDate("MM/DD/CCYY HH:mm:ss")));

TalendDate.getDate("MM/DD/CCYY HH:mm:ss") - This part is giving current date time in given format and I need this string as date data type. When I use parsedate, it is printing 1/1/2017.

Labels (1)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

Depends on the target database system.
For example, Salesforce allow you to push datetime as string.
Did you tried to populate the target field with "TalendDate.getCurrentDate()" which returns the current datetime as a date datatype?

View solution in original post

8 Replies
TRF
Champion II
Champion II

Hi,

A Date is a Date, a formated Date is a date represented by a String.

Can you explain a little more what's expectation?

 

System.out.println(TalendDate.formatDate("MM/dd/yyyy HH:mm:ss",TalendDate.getCurrentDate()));

Result (based on Europe/Paris TZ current datetime 😞

12/08/2017 14:45:47

 

 

su66
Contributor
Contributor
Author

Hi, Thanks for your response.

 

The formatted date that's a string need to be loaded to a database table where the filed datatype is date. So, the formatted date as a string is unable to get into the date field of the table.

TRF
Champion II
Champion II

Depends on the target database system.
For example, Salesforce allow you to push datetime as string.
Did you tried to populate the target field with "TalendDate.getCurrentDate()" which returns the current datetime as a date datatype?
su66
Contributor
Contributor
Author

Yes, I tried loading that directly. Because it prints time zone in it, I had invalid character issues. I will format this at the database end. Thank you 0683p000009MACn.png

TRF
Champion II
Champion II

You're welcome
Manoj_MUTHURAJA
Creator
Creator

Hello,

the above syntax TalendDate.formatDate("yyyyMMddHHmmss",TalendDate.getCurrentDate()) with the hours,
I used on my job,where there is a shift of 2 hours.For example by using the above syntax, when I insert a line in a table at 20/09/2019 8h00,but in my table the I see the line is inserted at 20/09/2019 6h00.

I don't why its happeneing .

Could someone tell me the reason or propose other syntax please?

roalro
Contributor III
Contributor III

Hi TRF.

 

Thanks for your reply.

 

But I want to charge this value in a variable for a properties file. How can I do that with Talend?

Manoj_MUTHURAJA
Creator
Creator

Hello,

You can use the composant tfixedflowinput and you create a column for example col1 and give value as TalendDate.getDate("yyyyMMdd") and tmaps is not compulsory to use it and to charge in your properties file,it depends on what kind of file format you will use it.It can be in txt,csv or dat etc.