SQL Table - Return a date 30 days before another date
Asked by Laurie Huth:

**Issue:** I am using the *Jira Issue/Filter* macro within the *Table Transformer* macro in a Confluence page. I currently have the following string. See below.

SELECT 'Key',  
FORMATWIKI(SUM('Build Date')) AS 'Build Date',  
FORMATWIKI(SUM(FORMATDATE('Due'))) AS 'Expected Impact Date',

Why displays the following table:

![Screenshot 2022-11-16 102010.png](https://community.atlassian.com/t5/image/serverpage/image-id/226073i0542525CF4E1CBD5/image-dimensions/329x197?v=v2 "Screenshot 2022-11-16 102010.png")

However, I don't want the current Build Date. I want to make my Build Date to be the **Expected Impact Date minus 30 days.**I think I need to do something with the function, DATEADD. However, it keeps returning an 'Invalid Date' in the cell where the new date should be.


Answers:
author: Natalie Paramonova [Stiltsoft]
body: Hi [@Laurie Huth](/t5/user/viewprofilepage/user-id/4825705) ,

To count dates that are "minus 30 days from the existing dates in the table", you may use the following SQL query:  

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

SELECT T1.'Date 1',  
FORMATDATE(DATE_SUB(T1.'Date 1', INTERVAL 30 DAY)) as 'Date 2'  
FROM T1

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

The date format for the [Table Transformer](https://docs.stiltsoft.com/display/TFAC/General+syntax+and+SQL+functions+available?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macro is set as "d M yy".

Hope this helps in your case.

comments: author: Laurie Huth
body: Thank you!

However, I'm still struggling with getting this to work. I have other SQL lines and I don't know how to incorporate this important line in. All attempts lead to a returned result of: **undefined NaN**in my table.

SELECT 'Key',  
FORMATWIKI(SUM('Summary')) AS 'Key Summary',  
FORMATWIKI(SUM('Due')) AS 'Due Date',  
**FORMATDATE(DATE_SUB('Due', INTERVAL 30 DAY)) as 'Date 30 days',**   
FORMATWIKI(SUM('Region Impact')) AS 'Regional Impact',

etc....


author: Katerina Rudkovskaya [Stiltsoft]
body: Hi [@Laurie Huth](/t5/user/viewprofilepage/user-id/4825705),   

Let's move the discussion to the [support portal](https://jsd.stiltsoft.com/servicedesk/customer/portal/2) then.  

We need to see your whole original table (all the headers and several rows visible) and an explanation of what you need to achieve with each column.  

The best way to share your data is to give us your Page Storage Format (upper right corner of the page -\> menu ... -\> View Storage Format, if you don't see the option, ask your Confluence administrator to do it for you). Then we'll be able to recreate exactly your data and help you with the custom query.  

P.S. Check the date format inside the Table Transformer macro once more as we've suggested in the first reply (Settings tab -\> Date format). It should be related to the date format in your table ("d M yy" for your and my screenshots).


author: Alex Koxaras _Relational_
body: Hi [@Laurie Huth](/t5/user/viewprofilepage/user-id/4825705)

Are you on cloud (as the tags state) or on prem? There isn't an SQL on cloud, unless there is a new app which allow SQL (doubt a bit)

comments: author: Laurie Huth
body: Oops. I am not on cloud. I just updated my question to clarify the issue. Thanks!


Tags: confluence-server

filter

sql

table

table-filter

table-filter-and-charts

table-transformer