Expand my Community achievements bar.

SOLVED

Order pages by date (Not created by or modified date)

Avatar

Level 4

We give all our news items/pages a date field through the Page Properties dialog. This xtype is datefield. So I can configure it to be MM-DD-YYYY or DD-MM-YYYY, etc. My question is how can I use the JCR SQL query language to order my query by this date field. I'm using 

ORDER BY datePosted DESC

Currently the date is stored as MM-DD-YYYY. It reads only the month value and orders it by that. How cna I make it read the whole date value?

1 Accepted Solution

Avatar

Correct answer by
Level 4

I was able to change the format of the DatePicker to YYYY-MM-DD and my original query worked to sort!

View solution in original post

3 Replies

Avatar

Level 10

This is the Syntax using JCR SQL2:

SELECT p.* FROM [nt:base] AS p WHERE ISDESCENDANTNODE('/') AND (p.[date] <> '' AND p.[date] > CAST('2015-11-30T00:00:01.000Z' AS DATE)) order by p.[date] asc

Source: 

https://wiki.magnolia-cms.com/display/WIKI/JCR+Query+Cheat+Sheet

Hope this helps... 

Avatar

Correct answer by
Level 4

I was able to change the format of the DatePicker to YYYY-MM-DD and my original query worked to sort!