0% found this document useful (0 votes)
1K views

Sort Date Field in XML Publisher Template

The report was not sorting dates correctly because the date field was formatted as text ("DD-MON-YYYY") when retrieved from the database. To fix this, the template was updated to convert the date to a number format (YYYYMMDD) before sorting. This allowed the records to be sorted properly by date.

Uploaded by

SuneelTej
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Sort Date Field in XML Publisher Template

The report was not sorting dates correctly because the date field was formatted as text ("DD-MON-YYYY") when retrieved from the database. To fix this, the template was updated to convert the date to a number format (YYYYMMDD) before sorting. This allowed the records to be sorted properly by date.

Uploaded by

SuneelTej
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Sort date field in XML Publisher template

I have been facing a continuous problem in a XML Publisher report. It seemed pretty trivial but I could not get it right. The report output had a date field and it was formatted while getting the data from the database to DD-MON-YYYY. Hence when the data came into the template it was interpreted as CHAR and the sorting was out of order. Although the data was sorted according to date from the database the output still did not show correctly. The output below shows Invoice Date, 01-Oct-09 before 01-Sep-09

Unsorted report After a lot of trying I got the idea to internally convert the date into numbers. The conversion would be YYYYMMDD. Once the date is converted to this number value and sorted as number, the records would be sorted properly. Hence I worked on the template.

Report template In the field, G_Line, which is the loop initiator I added the following after <?foreach?G_LINE_CLUSTER>, <?sort:concat(20,substring(TRX_DATE,8,2),(string-length(substringbefore(XXXJANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC, substring(TRX_DATE,4,3))) div 3) + 10,substring(TRX_DATE,1,2));ascending;datatype=number?> The code for G_LINE field looked like,

After the change the records were sorted according to Invoice date as required,

Report sorted by Invoice Date

You might also like