You are here: Re: [PHP] sorting dates with php « PHP « IT news, forums, messages
Re: [PHP] sorting dates with php

Posted by Andrι Medeiros on 12/21/05 21:48

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

On 12/21/05, Jim Moseby <JMoseby@nrbindustries.com> 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
>
>

 

Navigation:

[Reply to this 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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация