Sorting by date

QuestionsSorting by date
Richard asked 6 years ago

Date display required: d/m/y

How to sort in date order when clicking column order?

I have tried
$qry="select FROM_UNIXTIME(confirm_sent,'%d/%m/%y %a %H:%i') as confirm_sent_al , confirm_sent …."

$col["name"] = "confirm_sent_al";
$col["dbname"] = "confirm_sent";

2 Answers
Abu Ghufran answered 6 years ago

When you format date using sql function, it will be treated as string and sorted as string.
Perhaps, you are facing issue of sorting days first, month and then year.

If this is the issue, you can try changing it to

…. FROM_UNIXTIME(confirm_sent,'%Y-%m-%d %H:%i:%s') ….

And apply date formatting in grid settings: e.g.

$col["formatoptions"] = array("srcformat"=>'Y-m-d H:i:s',"newformat"=>'d/m/Y H:i');

Richard answered 6 years ago

Thank you very much!

To anyone else reading this, make sure to include

$col["formatter"] = "date";

before (or after?)

$col["formatoptions"] = array("srcformat"=>'Y-m-d H:i:s',"newformat"=>'d/m/Y H:i');

Your Answer

12 + 14 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?