Order pages by date (Not created by or modified date) | Community
Skip to main content
Level 3
August 5, 2016
Solved

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

  • August 5, 2016
  • 3 replies
  • 2546 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by squid267

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

3 replies

smacdonald2008
Level 10
August 5, 2016

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... 

squid267AuthorAccepted solution
Level 3
August 5, 2016

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

smacdonald2008
Level 10
August 5, 2016

Thxs for posting upur solution!