How to sort date when its format is like '10 - Feb -2022??
Asked by CYH:

The target date format is 11-Feb-2022.

But when I use this format, **the date sorting is based on number and then alphabet (believing it is a string now) .** Let me show you the picture.

I change the date format into **d M yy** in table edit page in setting and then it looks like the picture.

And one more thing : when the format is M - D -YYYY , there is 0 in front of some date cell, Please check the \[Pre Date\].

all data are from jira.

Here is the JQL

SELECT '++IMPORT++ ',  
FORMATWIKI(SUM('ITEM'+"\\n")) AS '++Item++ ',  
FORMATWIKI(SUM( 'Date'+ "\\n ")) as '++Date++ ',  
FORMATWIKI(sum('Pre Date'+"\\n" )) as '++Pre Date++ ',  
FROM (

SELECT 'Import', 'Item' ,

FORMATDATE('Date') as 'Date',

FORMATDATE('Pre Date') as 'Pre Date'

FROM T\* ORDER BY 'Item' , 'Date' ASC

) T1  
GROUP BY 'Item'

![image.png](/t5/image/serverpage/image-id/182899i8BFF22FA07A055A6/image-size/large?v=v2&px=999 "image.png")


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

You are right and the Date column is treated as a string data after the FORMATWIKI manipulations.

I'm not really sure what exactly you had into the original table coming from the Jira Issues macro, but I've created a regular Confluence table, copied your query with the ordering by 'Date' ASC and get the same result.

![Fri 10-5.png](https://community.atlassian.com/t5/image/serverpage/image-id/182926i93EDB5844768DB4A/image-size/large?v=v2&px=999 "Fri 10-5.png")

![Fri 10-6.png](https://community.atlassian.com/t5/image/serverpage/image-id/182927i32D17749CFA3829B/image-size/large?v=v2&px=999 "Fri 10-6.png")

The simplest option is to use the second Table Transformer: leave all the data manipulations in the first one and use the second one only for sorting.

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

![Fri 10-4.png](https://community.atlassian.com/t5/image/serverpage/image-id/182929iD78C7E3D799F8159/image-size/large?v=v2&px=999 "Fri 10-4.png")

Now we see that the dates are sorted correctly.

And don't forget to choose the corresponding Date Format in the Table Transformer macro settings:

![Fri 10-3.png](https://community.atlassian.com/t5/image/serverpage/image-id/182930i8F67EACC81701192/image-size/large?v=v2&px=999 "Fri 10-3.png")

And as you use our [Table Filter and Charts for Confluence](https://marketplace.atlassian.com/apps/27447/table-filter-and-charts-for-confluence&utm_source=atl_community?tab=overview&hosting=server) app, note that recently we've released a new macro - [Table Spreadsheet](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Table+Spreadsheet+macro?utm_source=atl_community). Please check out new Excel functionality right in Confluence: the macro is available for Cloud and Server/DC.

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


author: CYH
body: Hi Katerina

your suggestion of " to format data, then sort the dates when they are still in separate cells and then group the already sorted fields by something " works so well !

I am stuck in group them first.

Thank you so much !


author: CYH
body: I see. let me try to sort the date first and then group them. Will give you feedback later. Thanks a lot


author: Katerina Kovriga {Stiltsoft}
body: The Date format inside the first Table Transformer macro settings is the result format that comes from the FORMATDATE function that you use in the first query.

In the first question you said that the desired output is 11-Feb-2022, so use the dd-M-yyyy format twice.

The first variant uses two different formats: at first you change the date to the YYYY-MM-DD and then sort these dates as d M yy.

The second variant seems better and should be working fine.

I also paid attention that you try to sort several dates inside one cell - this may be the problem. The Table Transformer macro works with tables as with SQL databases, I mean with cells, not with aggregated pivot tables (in my example I used non-grouped table).

Try to format your data, then sort the dates when they are still in separate cells and then group the already sorted fields by something.


author: CYH
body: HI Katerina,

I try to use the second Table Transformer but it doesn't work.

Here is the inside (The first one) Table and the Date format in settings is '**YYYY-MM-DD':** ![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/182933iF3EBCF96574BEF3E/image-size/large?v=v2&px=999 "image.png")

Here is the outside table transformer:--the result of date format is the same

and the date format in setting is**d M yy (1 Apr 2022)** ![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/182936iF66329B75C0FED76/image-size/large?v=v2&px=999 "image.png")

**Another Try:**

Set first table date format as d M yy

result : disorder sorting of Due Date

Continue to set second table date format as d M yy

result : disorder sorting of Due Date

Could you check which part I did wrong?


Tags: jira

macro

table