Re: Sorting times
| From: | Shawn McKenzie | Date: | Sat, 14 Feb 2009 21:50:58 +0000 |
| Subject: | Re: Sorting times | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-288271@lists.php.net to get a copy of this message | ||
John Corry wrote:
> 1. convert the string representation of times to timestamps using
> strtotime()
> 2. sort the timestamps
> 3. display the timestamps as strings using date('format', timestamp)
>
> Would that work?
>
> John Corry
> email: jcorry@gmail.com
>
>
>
>
> On Feb 14, 2009, at 4:07 PM, tedd wrote:
>
>> Hi gang:
>>
>> Anyone have/know a routine that will sort an array of times?
>>
>> For example, a function that would take an array like this:
>>
>> time[0] ~ '1:30pm'
>> time[1] ~ '7:30am'
>> time[2] ~ '12:30pm'
>>
>> and order it to:
>>
>> time[0] ~ '7:30am'
>> time[1] ~ '12:30pm'
>> time[2] ~ '1:30pm'
>>
>>
>> Cheers,
>>
>> tedd
>>
>>
>> --
>> -------
>> http://sperling.com
>> http://ancientstones.com
>> http://earthstones.com
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
Yes, I would probably store and manipulate times as a timestamp and then
format them for printing, but then there would always be a date
associated with the timestamp as well (whether you need it or not). So
you could store them in 24hr time format and sort those and then format
to display in the 12 hour format.
--
Thanks!
-Shawn
http://www.spidean.com