cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting Date

Former Member
0 Kudos

Hi,

I have created A Web Dynpro Table Called 'Arrivals' and I am sorting this table using TableSorter.java class.

One of the Field in my table is 'Arrival Dateu2019 - Which is of type u201CStringu201D (in the Context)

I am using MS - SQL Backend where ArrivalDate has been declared to be of type "Date" - sql (in the Data Base)

I am getting the ArrivalDate from the Backend and Applying The Below mentioned Date Format (i.e, "dd-MM-yyyy");

TimeZone tz = TimeZone.getTimeZone("GMT+05:30");

SimpleDateFormat formatter =(SimpleDateFormat)DateFormat.getDateTimeInstance (DateFormat.LONG, DateFormat.LONG, Locale.US);

formatter.setTimeZone(tz);

formatter.applyPattern("dd-MMM-yyyy");

After Formatting I am setting the context Attribute 'Arrival Date' with the Formatted Date, say "04-Nov-2008".

After Sorting, Since My Table Column is String the 'Arrival Dateu2019 is also getting sorted as String - as shown below (Sorted in Ascending Order)

04-Nov-2008

06-Oct-2008

07-Nov-2008

12-Jul-2008

O4u2013Nov is getting Sorted Before 06-Oct in ascending order which is wrong.

I cannot declare the context field u2018Arrival Dateu2019 as Date because if I do so, No doubt it will sort properly, but the format will be gone and I want to display it in the format u201Cdd-MMM-yyyyu201D and not u201Cmm/dd/yyyyu201D(Sql Date)

7/12/2008

10/6/2008

11/4/2008

11/6/2008

So I want to retain the Format u201Cdd-MMM-yyyyu201D and sort the Column according to date and not as String.

Kindly let me know if there is any possible solution for this.

Regards,

Shilpa B.V

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Create a simple type of date and represent the date format you want in the representiion part and map this simple type to an attribute value and then do the sorting operation

Regards

Padma N

Former Member
0 Kudos

Hi Padma,

Thanks for your quick response.

I couln't have found a better solution than this.

My problem is solved. Thank you.

Regards,

Shilpa B.V

Former Member
0 Kudos

Hi,

Why not a comparator of your own

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Comparator.html

Regards

Ayyapparaj

Answers (0)