Table Transformer | Highlighting Dates past due
Asked by Tommy Str?mme:

Hi,   
I have searched the forum and also used chatgpt but cant really get it to work.  

I have a table with a date column that is called "Updated".  

I simply want to have all dates older then 7 days turn red, otherwise they should stay green.   

This code gives me no errors, but it will list all dates (even those 3 weeks ago) green:  

SELECT \*,  
FORMATWIKI("{cell:bgColor=" +  
CASE  
WHEN T1.'Updated' IS NULL THEN "#FFFFFF"  
WHEN CAST(T1.'Updated' AS DATE) \< DATE_SUB(CAST("today" AS DATE), INTERVAL 7 DAY) THEN "#FA7E70"  
ELSE "#8FCA7D"  
END  
+ "}" + FORMATDATE(T1.'Updated') + "{cell}")  
AS 'Updated'  
FROM T1  

Can anyone point me in the right direction? Date format is fine btw.  

Regards

/Tommy  


Answers:
author: Stiltsoft support
body: Hi [@Tommy Str?mme](/t5/user/viewprofilepage/user-id/5381475) ,

You may also search the Atlassian Community, there are similar cases with the Table Transformer, for example, this one: <https://community.atlassian.com/t5/Confluence-questions/Conditional-Formatting-for-Confluence-tables/qaq-p/1568284>

![Wed 9-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/310512iCD5A7F7FDFB8AD54/image-size/large?v=v2&px=999 "Wed 9-1.png")SELECT \*,  
FORMATWIKI("{cell:bgColor=" +  
CASE  
WHEN T1.'Updated' IS NULL THEN "Grey"  
WHEN DATEDIFF(day,"today",T1.'Updated') \<= -7 THEN "Red"  
ELSE "Green"  
END  
+ "}" + FORMATDATE(T1.'Updated') + "{cell}")  
AS 'Updated'  
FROM T1

![Wed 9-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/310514i18DCD1603775F9E2/image-size/large?v=v2&px=999 "Wed 9-2.png")Hope it helps your case.

comments: author: Tommy Str?mme
body: Ahh..that was just brilliant!!! Thank you so much!!! Awesome!

One final question.. do you know why on earth the date now splits into two lines? In the screnshot is the same table with table filters on top and without on the bottom ( i swapped Green for White (looked better)  

Regards

Tommy

![Screenshot 2.png](https://community.atlassian.com/t5/image/serverpage/image-id/310517i54468EDB41FBB4B8/image-size/large?v=v2&px=999 "Screenshot 2.png")


author: Stiltsoft support
body: I think it's because your table is really wide. As there is a space in the date cells and other columns contain a lot of data, Confluence decided to split dates into two lines.

You may set a predefined width for this column though <https://docs.stiltsoft.com/tfac/cloud/advanced-table-cells-formatting-58426218.html#Advancedtablecellsformatting-Changingcolumnwidth>


author: Tommy Str?mme
body: Hmm.. tried to add as it said there, but if I change it to 80 og 480 it stays the same. No errors though.  

SELECT \*,  
FORMATWIKI("{cell:width=80px}" + 'Updated'+ "{cell}") AS 'Updated',  
FORMATWIKI("{cell:bgColor=" +  
CASE  
WHEN T1.'Updated' IS NULL THEN "Grey"  
WHEN DATEDIFF(day,"today",T1.'Updated') \<= -7 THEN "Red"  
ELSE "White"  
END  
+ "}" + FORMATDATE(T1.'Updated') + "{cell}")  
AS 'Updated'  
FROM T1


author: Tommy Str?mme
body: Figured it out!  

SELECT \*,  
FORMATWIKI("{cell:width=150px\|bgColor=" +  
CASE  
WHEN T1.'Updated' IS NULL THEN "Grey"  
WHEN DATEDIFF(day, "today", T1.'Updated') \<= -7 THEN "Red"  
ELSE "White"  
END  
+ "}" + FORMATDATE(T1.'Updated') + "{cell}")  
AS 'Updated'  
FROM T1  


author: Stiltsoft support
body: Yes, the first variant at first set the width and then rewrote it with the second part of your SQL.

Glad it works for you!


Tags: confluence-data-center

data-center

table

table-filter

table-filter-and-charts

table-filter-charts-spreadsheets

table-transformer