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)
1 Solution

Accepted Solutions
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)

View solution in original post

24 Replies
manodwhb
Champion II
Champion II

@joe86,you can compare this way in tmap.

 

 

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 @manodwhb
Let me try this. if there is a difference in the format of the date in "row2.date1", will this comparision work. I am asking this since the date is coming from MongoDB and i am comparing it with "current date + 7". ??
manodwhb
Champion II
Champion II

@joe86,what date format are you getting form Mongo DB?

manodwhb
Champion II
Champion II

@joe86,still do you have issue?

joe86
Contributor
Contributor
Author

@manodwhb

Hi, sorry for delay. I am getting error as below:

0683p000009M0f6.jpg

 

can you please help on this??

joe86
Contributor
Contributor
Author

also, do i need to change the data type of this date column to "string" after applying this formula??

manodwhb
Champion II
Champion II

@joe86,yes the output data type is sting. row2.date1 id date format.

 

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

Hello @manodwhb,
please ignore all my previous.
in your command, you re checking if the incoming date is equal to (current date + 7). But i need, if the incoming date is LESSER THAN (current date + 7), the i need to display the date as it is. And if the incoming date is GREATER THAN (current date + 7), then i need to display "Will expire in 1,2,3 days".
manodwhb
Champion II
Champion II

@joe86,i am checking that the incoming date is lesser than the current+7 days ,since i was using "==1" in the expresion.