Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
joe86
Contributor
Contributor

Convert DATE (date and time) to STRING (date and time)

Hi All,

I need to convert a DATE to STRING with a condition.

I need to check if the incoming date (date with timestamp) is lesser than (current date + 7) days. If yes, then i need to pass a string like "To Be Expired" Else, I need to retain the incoming date (date with timestamp) value as it is. My incoming date column is of DateType DATE.

 

Can someone please help me to achieve this in tMap??

Labels (2)
24 Replies
manodwhb
Champion II
Champion II

@joe86,then use the below way.

 

TalendDate.compareDate(TalendDate.addDate(TalendDate.getCurrentDate() ,7,"dd") ,row2.date1)==-1 ? "To Be Expired" :TalendDate.parseDate("dd/MM/yyyy", row2.date1)

joe86
Contributor
Contributor
Author

thanks for your patience. But still i am getting the same error.
I have changed my tMap output data type of date column to string, and getting same error again.
manodwhb
Champion II
Champion II

@joe86, use the below one

 

TalendDate.compareDate(TalendDate.addDate(TalendDate.getCurrentDate() ,7,"dd") ,row2.date1)==-1 ? "To Be Expired" :TalendDate.formatDate("dd/MM/yyyy", row2.date1)

joe86
Contributor
Contributor
Author

hello,

still facing the same error. see below the screenshot on how i have given in tMap.

I have changed the data type to string also.

0683p000009M1EW.jpg

manodwhb
Champion II
Champion II

@joe86,in the expression else part use the TalendDate.formatDate("dd/MM/yyyy", row2.date1) 

joe86
Contributor
Contributor
Author

Thanks a lot dude. Its working now.
But a small issue.. If the incoming date is NULL/Blank, still the output is getting populated as "to be expired" instead of Null/Blank.
manodwhb
Champion II
Champion II

@joe86, handle below way for nulls.

row2.date1==null ?row2.date1 : TalendDate.compareDate(TalendDate.addDate(TalendDate.getCurrentDate() ,7,"dd") ,row2.date1)==-1 ? "To Be Expired" :TalendDate.formatDate("dd/MM/yyyy", row2.date1)

manodwhb
Champion II
Champion II

@joe86,please accept the solution and provide Kudos also 0683p000009MACn.png

joe86
Contributor
Contributor
Author

i gave like below since the date column data type is string in target side:
Organiser.CRBExpiryDate== null ? TalendDate.formatDate("dd/MM/yyyy", Organiser.CRBExpiryDate):TalendDate.compareDate((TalendDate.addDate(TalendDate.getCurrentDate(),7,"dd")) ,Organiser.CRBExpiryDate)==1 ? "To Be Expired" :TalendDate.formatDate("dd/MM/yyyy", Organiser.CRBExpiryDate)

but getting NULL pointer exception error.
manodwhb
Champion II
Champion II

@joe86,

 

you should change below way.

 

Organiser.CRBExpiryDate== null ? Organiser.CRBExpiryDate : TalendDate.compareDate((TalendDate.addDate(TalendDate.getCurrentDate(),7,"dd")) ,Organiser.CRBExpiryDate)==1 ? "To Be Expired" :TalendDate.formatDate("dd/MM/yyyy", Organiser.CRBExpiryDate)