How to create days between dates for multiple scenarios in a confluence table
Asked by John Allen:

I have a table constructed in confluence. It consists of different dates that a new Feature moves through the software development process from initiation to release. To the right, there are 4 duration columns that I want to show the date differential from phase to phase of the process.

Using the Table Transformer macro, the SQL query in the 2nd image below works. What I dont know is how to modify the SQL query to allow me to have 4 different date diff durations in the last 4 columns on the right?

**1. Table prior to calculations.**

![Photo 0.JPG](/t5/image/serverpage/image-id/172750i15483B426F5D416C/image-size/large?v=v2&px=999 "Photo 0.JPG")

**2. SQL Query used. How to I add additional queries for the other 3 duration fields I want datediff outputs for?**

![Photo 1.JPG](/t5/image/serverpage/image-id/172751i5AFC4A859CF3383A/image-size/large?v=v2&px=999 "Photo 1.JPG")

**3. I edited the worklog settings.**

![Photo 2.JPG](/t5/image/serverpage/image-id/172752i2015EACDFCFE60F0/image-size/large?v=v2&px=999 "Photo 2.JPG")

**4. The output of the SQL query**

![Photo 3.JPG](/t5/image/serverpage/image-id/172753i9138D046871C64A5/image-size/large?v=v2&px=999 "Photo 3.JPG")


Answers:
author: Katerina Kovriga {Stiltsoft}
body: Hi [@John Allen](/t5/user/viewprofilepage/user-id/4664907) ,

You've got the SQL query right - just add other DATEDIFF expressions subsequently:

![Wed 4-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/172791i23E52E2B33B477BA/image-size/large?v=v2&px=999 "Wed 4-1.png")

SELECT \*,  
DATEDIFF(day, 'SRF Submitted', 'First Sprint Started') + 1 + " days" as 'SRF to First Sprint Duration',  
DATEDIFF(day, 'First Sprint Started', 'UAT Signoff') + 1 + " days" as 'First Sprint to UAT Signoff Duration',  
DATEDIFF(day, 'UAT Signoff', 'Production Release') + 1 + " days" as 'UAT Signoff to Release Duration',  
DATEDIFF(day, 'SRF Submitted', 'Production Release') + 1 + " days" as 'Duration of Release'  
FROM T\*

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

And here is another [example](https://community.atlassian.com/t5/Jira-Software-discussions/display-sprint-status-as-Ongoing-Not-started-Finished/td-p/1876949) for you from the recent Community thread - how to set statuses based on dates' difference.

comments: author: John Allen
body: Hi [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746)

Much simpler than I was thinking. That worked perfectly - thank you!!!

To improve this further, is there an easy way to display the text "No SRF" in the 'SRF to First Sprint Duration' column if the 'SRF Submitted' field is NULL? Same logic would apply for the other duration fields should any needed source data be null in the table.

Thank you!!!


author: Katerina Kovriga {Stiltsoft}
body: You may try the following workaround - wrap the second Table Transformer macro on the top of the first one (so we won't mess up our query with DATEDIFF and will refer to a new big table). For Server/Data Center it is done directly, for Cloud - via the [Table Toolbox](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Table+Toolbox+macro) macro.

![Wed 5-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/172910iD77557D0DA319A9B/image-size/large?v=v2&px=999 "Wed 5-1.png")

Then you may use the following structure to replace the unwanted output with a more user-friendly text:

SELECT \*,  
CASE WHEN T1.'SRF to First Sprint Duration' LIKE "NaN days"  
THEN "Not SRF"  
ELSE T1.'SRF to First Sprint Duration'  
END  
AS 'SRF to First Sprint Duration'  
FROM T\*

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


author: Katerina Kovriga {Stiltsoft}
body: And if you use empty cells when there are no dates, you may use a slightly modified construction:

![Wed 5-3.png](https://community.atlassian.com/t5/image/serverpage/image-id/172916iB0C88BB857C8BA9B/image-size/large?v=v2&px=999 "Wed 5-3.png")

SELECT \*,  
CASE WHEN T1.'SRF Submitted' IS NULL  
THEN "Not SRF"  
ELSE T1.'SRF to First Sprint Duration'  
END  
AS 'SRF to First Sprint Duration'  
FROM T\*

![Wed 5-4.png](https://community.atlassian.com/t5/image/serverpage/image-id/172917iA8A2FCB53CBBEE61/image-size/large?v=v2&px=999 "Wed 5-4.png")

Here we check not the result output, but the source column and then change the column with the DATEDIFF formula.


author: Katerina Kovriga {Stiltsoft}
body: Hi there,

As this question mentions our [Table Filter and Charts for Confluence](https://marketplace.atlassian.com/apps/27447/table-filter-and-charts-for-confluence?tab=overview&hosting=cloud&utm_source=atl_community) app, we are happy to introduce its new macro -- [Table Spreadsheet](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Table+Spreadsheet+macro?utm_source=atl_community).

The new macro allows you to work with fully functional Excel spreadsheets right in Confluence.

You'll be able to use cells' formulas, filters, conditional formatting, etc., create pivot tables and charts from the page view and edit mode.

The Table Spreadsheet macro is available for Cloud and Server/Data Center.

![](https://docs.stiltsoft.com/download/attachments/83100938/Conditional%20formatting.png?version=1&modificationDate=1641987630000&api=v2&effects=border-simple,shadow-kn)


Tags: date

diff

macro

table-transformer