Developer forum

Forum » CMS - Standard features » Cant sort on datetime field in query

Cant sort on datetime field in query

Andreas Pettersson
Reply

Hi,

I have build an custom index which has a column that is "System.DateTime". 

 

In my custom Indexbuilder class i set the value for that property like this beacuase it need to be a string in the "IndexDocument" class:

 


And in my Query i have a sort on that field in descending order but it not seem to sort it.

 

On my page it renders in this order:

 

And in my querypublisher page i also sort in descending order:

 

Any suggestions what can be wrong?


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Andreas

Old thread, I know, but came across it.

You should store the date as a string for sorting - using sortable format. 

So the index fields hould be string, and the value you store is the date tostring as sortable:

https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings#Sortable

 
Andreas Pettersson
Reply

Hi, 

Thanks this has been solved now and works as expected.

Regards

Andreas

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

Is this type of change something that can be handled using built-in functionality?

Like a specific FieldType in the Index? It seems like a pretty usual scenario to be included in the standard functionality.

Thank you,
Adrian

 

You must be logged in to post in the forum