djiga4me
djiga4me

Reputation: 345

Indexing with a Date field (as a String) in ClientDataSet

on Delphi XE2, I have a ClientDataSet which have many fields as Name, ... It have a field named Date, as value type String. Containing a Date (dd/mm/yyyy) I want to print content of ClientDataSet, using FastReport. I want before to sort content ascending according to the Date field. I'm using index. But when doing this, sorting does only sorts fields according to the content of the Date string before the "/". form example dates like : 12/11/2012, 15/10/2012, 01/12/2012 are sorting like this : 01/12/2012 - 12/11/2012 - 15/10/2012. ny idea how doing this correctly ?!

Upvotes: 0

Views: 1011

Answers (2)

Fabricio Araujo
Fabricio Araujo

Reputation: 3820

You have some options:

  • Bring the field as a DateTime field. You would have to change the original SQL to that.
  • Do what Marjan suggested, bringing that string field formatted on an ISO-like style (which allows for the field to be ordered cronologically when string sorting is aplied) and creating an calculated field for user-display formatting.
  • Creating a new field on the TDatasetProvider's OnGetRecords event and populating it as a Date field.
  • Similar as above but creating a string field with the date formatted in ISO-Like style.

I personally suggest the first approach if possible.

Upvotes: 0

Uwe Raabe
Uwe Raabe

Reputation: 47714

The sorting is correct! As you have a string field, the sorting is made like strings are sorted i.e. from left to right. If you want it sorted by Date you need either a date field or sort the string representation like yyyy/mm/dd.

Upvotes: 3

Related Questions