Opened 9 years ago

Closed 6 years ago

# Sort as a date

Reported by: Owned by: Renne Robert Corsaro normal DateFieldPlugin normal Itamar Ostricher 0.11

### Description

Actually, the fields are sorted as a 'text' field. It will be nice if we can sort the 'date' fields as a real date.

### comment:1 in reply to:  description ; follow-up:  2 Changed 9 years ago by anonymous

Actually, the fields are sorted as a 'text' field. It will be nice if we can sort the 'date' fields as a real date.

Workaround: use format=ymd. Sorting works well then.

### comment:2 in reply to:  1 Changed 9 years ago by anonymous

Actually, the fields are sorted as a 'text' field. It will be nice if we can sort the 'date' fields as a real date.

Workaround: use format=ymd. Sorting works well then.

Thanks! I am already using that. But here (in Brazil) it is uncommon the form 'ymd'. It will be better for the end users to be able to insert the data in 'dmy' form and have it sorted correctly.

### comment:3 in reply to:  description Changed 8 years ago by hju@…

Actually, the fields are sorted as a 'text' field. It will be nice if we can sort the 'date' fields as a real date.

I faced the same problem in reports. Here is my solution: I transform the datestring to time in the sql-query of the reports!

SELECT ... cCur.value AS Current_Due, ...
FROM ticket t
LEFT OUTER JOIN ticket_custom cDue ON (t.id = cDue.ticket AND cDue.name = 'due_date')
... ORDER BY
strftime('%s',substr(cDue.value,7,4)||"-"||substr(cDue.value,4,2)||"-"||substr(cDue.value,1,2))


my custum ticket is named due_date.

By the way: you can filter tickets by comparing the Due date i.e. with the actual date.

... < strftime('%s',date('now'))


### comment:4 Changed 8 years ago by terje

Here is micro (Trac) patch to enable sorting in custom query results. Postgres only + hardcoded to due_assign, due_close in DD-MM-YYYY format, I put it up so others have a place to start if interested:

• ## trac/ticket/query.py

 #        one, if text, we do 'else' if name in ('id', 'time', 'changetime'): sql.append("COALESCE(%s,0)=0%s," % (col, desc)) elif name in ('due_assign', 'due_close'): # invert sort order mydesc = desc!=' DESC' and ' DESC' or '' sql.append("TO_TIMESTAMP(COALESCE(%s, '01-01-1970'), 'DD-MM-YYYY')%s," % (col, mydesc)) else: sql.append("COALESCE(%s,'')=''%s," % (col, desc)) if name in enum_columns:

### comment:5 Changed 8 years ago by Robert Corsaro

Owner: changed from Noah Kantrowitz to Robert Corsaro

### comment:7 Changed 6 years ago by Itamar Ostricher

Cc: Itamar Ostricher added; anonymous removed

### comment:8 Changed 6 years ago by Ryan J Ollos

Resolution: → fixed new → closed

Update on plugin development: It will not be the aim of DateFieldPlugin to support a true date type, rather, just provide a datepicker for input fields. See #8964 for more details. True date type support is coming to the Trac core in the near future (see t:#1942).

### comment:9 Changed 6 years ago by Ryan J Ollos

Resolution: fixed closed → reopened

### comment:10 Changed 6 years ago by Ryan J Ollos

Resolution: → wontfix reopened → closed

### Modify Ticket

Change Properties