How to sort date when its format is like '10 - Feb -2022‘?

CYH February 10, 2022

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

 

1 comment

Katerina Kovriga {Stiltsoft}
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 10, 2022

Hi @CYH ,

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

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

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

 

And as you use our Table Filter and Charts for Confluence app, note that recently we've released a new macro - Table Spreadsheet. Please check out new Excel functionality right in Confluence: the macro is available for Cloud and Server/DC.

Like # people like this
CYH February 11, 2022

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

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

 

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? 

Katerina Kovriga {Stiltsoft}
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2022

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.

CYH February 11, 2022

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

CYH February 11, 2022

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 !

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events