Time - str_to_date

i have a time field in my table. it is of varchar data type.

i want compare the time between given times.

my stored time format is 09:25:01 am.

is there any way to compare my time field ?

i don t have any idea about mysql STR_TO_DATE function…
will it be usefull for my above problem…

please help me up to try it out…

On 12 March 2010 09:00, Newb N. [email protected] wrote:

i have a time field in my table. it is of varchar data type.
i want compare the time between given times.
my stored time format is 09:25:01 am.
is there any way to compare my time field ?

You asked this two days ago…

i don t have any idea about mysql STR_TO_DATE function…
will it be usefull for my above problem…

Probably - if your DB is MySQL. The function turns a string into a
date and you have a string that you need turned into a date.

please help me up to try it out…

Have you tried it? What happens? If you’ve got some way with it, and
have a code example that doesn’t quite work, then maybe we can work
from there.

Colin L. wrote:

On 12 March 2010 09:00, Newb N. [email protected] wrote:

i have a time field in my table. it is of varchar data type.

i want compare the time between given times.

As was previously suggested you should at least consider changing the
data type of the field in the db. I did not see any comment from you
on this suggestion in the previous thread.

Colin

now i m going to store the time 24 hour format…

so is there any funtion to convert the 12hour time to 24 hours

On 12 March 2010 09:00, Newb N. [email protected] wrote:

i have a time field in my table. it is of varchar data type.

i want compare the time between given times.

As was previously suggested you should at least consider changing the
data type of the field in the db. I did not see any comment from you
on this suggestion in the previous thread.

Colin

On 12 March 2010 09:27, Newb N. [email protected] wrote:

now i m going to store the time 24 hour format…

so is there any funtion to convert the 12hour time to 24 hours

You haven’t got a “Time” you’ve got a “STRING”… anything you do to
it, you’re going to have to do some work - and if your choice is to
change a 12hr clock string into a 24hr clock string, I don’t see that
makes any difference to your problem, which was about how to search
based on time…

Either:

a) Look at the SQL commands for the DB you’re using which manipulate
strings and dates.
b) Change how you store the data into something that can be compared
easily and reliably (so either a DB time/datetime field, or an integer
of “minutes from midnight”) - anything but a string.

On 12 March 2010 09:27, Newb N. [email protected] wrote:

Colin

now i m going to store the time 24 hour format…

so is there any funtion to convert the 12hour time to 24 hours

You might be able to use DateTime.strptime to convert to DateTime
which you can then convert to whatever format you want. See

for an example.

Colin