<![CDATA[ Datepicker + Ditto orderedBy - MODX Community Forums]]> https://forums.modx.com/thread/?thread=42827 <![CDATA[Re: Datepicker + Ditto orderedBy]]> https://forums.modx.com/thread/42827/datepicker-ditto-orderedby#dis-post-247593
<?php
if (!function_exists('sortByDatePicker')) {
    function sortByDatePicker($a_doc, $b_doc) {
        $a_stamp = strtotime($a_doc['date']);
        $b_stamp = strtotime($b_doc['date']);
        return ($a_stamp < $b_stamp ? -1 : ($a_stamp > $b_stamp ? 1 : 0));
    }
}

$orderBy['custom'][] = array('date', 'sortByDatePicker');
$ditto->advSort = TRUE;
?>

where ’date’ stands for the name of TV holding user-inserted date.

And finally, Ditto call with custom sort:
[[Ditto? &parents=`...` &display=`...` &tpl=`...` &extenders=`sortByDatePicker`]]
]]>
Alik Jun 02, 2010, 06:38 PM https://forums.modx.com/thread/42827/datepicker-ditto-orderedby#dis-post-247593
<![CDATA[Datepicker + Ditto orderedBy]]> https://forums.modx.com/thread/42827/datepicker-ditto-orderedby#dis-post-247592
I’m using the datepicker to allow users to select a date. But I also want to use this field as the sortBy in Ditto. However, it is sorting them alphabetically due to the MM dd, YYYY format that I’m outputting the dates on the front end.

Is there any way to display the date as Jun 3, 2010 and ask Ditto to sort based on another format like YYYY-MM-DD? Or would I just have to create two separate template variables?]]>
ambaxter Jun 01, 2010, 01:49 PM https://forums.modx.com/thread/42827/datepicker-ditto-orderedby#dis-post-247592