kwtow has asked for the wisdom of the Perl Monks concerning the following question:

Hi dear all,

I have a problem which I need help:

I have a mysql database with one of the col taking down the date and time it have been entered in the database, that col is in datetime format ('0000-00-00 00:00:00').

what I need to do here is to select all the row which is before 12am, which mean the date doesn't matter, as I m only looking at the time.

Is there any sql query or method to directly select all the row that meet my requirement without spliting my col or convert my col into other data type.

thanks and best regard.
  • Comment on selecting mysql data on time comparision

Replies are listed 'Best First'.
Re: selecting mysql data on time comparision
by Zaxo (Archbishop) on Nov 17, 2002 at 05:00 UTC

    If I understand what you want ( morning callers :), you can use the MySQL HOUR() function:

    my $earlybirds = "SELECT foo, bar, baz FROM thedata WHERE HOUR(themoment) < 12";
    You may want to replace '12' with ? if you will be interested in other times.

    The MySQL docs, under 'Reference / Functions', will repay a browse. The BETWEEN() function would be useful for generalizing this query.

    After Compline,
    Zaxo

      thanks it works