Re: sorting dates with php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You COULD sort them if the date was stored backwards, ie. Year/Month/Day

On 12/21/05, Jim Moseby <JMoseby@xxxxxxxxxxxxxxxxx> wrote:
> > 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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux