469,081 Members | 1,871 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,081 developers. It's quick & easy.

Sort by time in text string field (hh:mm:am/pm format)

Hi,

I have a group of records that I need to sort by time field. The time
field is a text string (should've been a date/time - I know -doh!) I
was wondering if anyone knew how to write a query to sort in Ascending
order with the earliest appearing first.

The times are stored as follows:

10:30pm
11:30pm

etc.

Many, many thanks to anyone who can help with this one. Cheers.
Jul 20 '05 #1
2 3447
00steve wrote:
I have a group of records that I need to sort by time field. The time
field is a text string (should've been a date/time - I know -doh!)


Is it impossible to convert the string field to be time field? This
should be possible with few queries on database, but does the
application logic allow it, or if not, can the logic be changed or not?

And do you have leading zeros or not, for example: "5:08pm" or "05:08pm"?
Jul 20 '05 #2
29****@tay.ac.uk (00steve) wrote in message news:<df**************************@posting.google. com>...
I have a group of records that I need to sort by time field. The time
field is a text string (should've been a date/time - I know -doh!) I
was wondering if anyone knew how to write a query to sort in Ascending
order with the earliest appearing first.

The times are stored as follows:

10:30pm
11:30pm


Try

ORDER BY
IF(INSTR(time_field, 'pm'), 12*60*60, 0) + TIME_TO_SEC(time_field) ASC

--
felix
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by 00steve | last post: by
3 posts views Thread by Barney | last post: by
1 post views Thread by Nerds | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.