Reply to RE: [PHP] sorting dates with php

Your name:

Reply:


Posted by Jim Moseby on 12/21/05 21:22

> Have a load of dates in the format DD/MM/YY. Thet are stored
> as a VARCHAR on
> a mysql DB.
>
> I need a way to sort them into order(most recent first)
>
>
> Using the QUERY $query = "SELECT doc_date FROM papers ORDER
> BY doc_date
> DESC";
>
> this just arranges them by day. e.g
>
>
> 30/12/2005
> 30/11/2005
> 22/12/2005
> 19/12/2005
> 17/12/2005
> 12/12/2005
> 10/12/2005
> 06/12/2007
> 06/09/2002
> 05/12/2005
> 05/09/2005
>
>
>
> Now I have tried to use strtotime() but I find this needs a
> timezone (GMT)
> to work and I don't know if the server supports it. Also I
> find strototime()
> and mktime() very confusing and a things go wrong of you work
> in GMT because
> we also have Brittish Summer Time where the clocks get put
> back/forward at
> certain time of the year.
>
> Is there a simple function like sort() that could do it??
>

Hi!

Its a real shame your dates aren't stored in a DATE type field instead of
VARCHAR, because you can just sort them in your query with "order by DATE".
If its possible, you would really benefit by converting them and storing
them in the proper DATE type field.

That being said, I suppose you could "explode()" them into an array then
figure out how to sort them from there.

JM

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация