Forums

Sort by date not working

marklandry 02 Aug, 2011
Hi, I have a form that enters the date in the following format:

month/day/year

And I'm trying to order the results by date DESC

However, the systems sees the following date "09/11/1009" as a full number, so that date shows up before, say, 01/01/2011, because it looks like a bigger number - does that make sense?

Anyway, my sorting is all jacked up. Is there another format I can use that the system will read more accurately?

Thanx

Mark
GreyHead 03 Aug, 2011
Hi Mark,

To get dates to sort correctly you either have to save them as a YYYY/MM/DD string or as a DATE type. Neither MySQL or ChronoForms are clever enough to sort a MM/DD/YYYY date on their own.

I'd be inclined to switch the column type to DATE. Either method does mean adding code to convert the displayed date back and forth.

Bob
marklandry 04 Aug, 2011
Hi Bob,

I've got the dates all switched to the format I need so I get eg 2011/08/01

However, is there a way to strip the 2011/ (ie the first 5 in the string)?
I know how to use substr but not how to apply it in CC.

Thanx

Mark
GreyHead 05 Aug, 2011
Hi Mark,

In the body section instead of {date} please try <?php echo substr($MyRow->date, 5); ?>

Bob
This topic is locked and no more replies can be posted.