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

Five Stars

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.

Tags (2)

Accepted Solutions
Forteen Stars TRF
Forteen Stars

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

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?

TRF

All Replies
Forteen Stars TRF
Forteen Stars

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

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

 

 


TRF
Five Stars

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

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.

Forteen Stars TRF
Forteen Stars

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

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?

TRF
Five Stars

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

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 Smiley Happy

Forteen Stars TRF
Forteen Stars

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

You're welcome

TRF