Skip to main content
May 30, 2010
Question

Query help

  • May 30, 2010
  • 1 reply
  • 304 views

I have the following entries in my db:

tbl_jobs

=============================

jid                                   date

=============================

1                                   05-13-2010

2                                   05-13-2010

3                                   05-05-2010

4                                   04-13-2010

5                                   03-05-2010


I am trying to figure out a query, that will only give me the entries for the month "05", does anyone know how i could do that?

I am using coldfusion 9 with mysql

    This topic has been closed for replies.

    1 reply

    existdissolve
    Inspiring
    May 30, 2010

    MySQL has a TON of date/time functions that will allow you to get the month from a date and use it in an expression.

    http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

    For example, if your column is "date", you could do a query like so:

    <cfquery name="qmonths" datasource"...">

         select jid,date,...

         from tbl_jobs

         where month(date) = '5'

    </cfquery>

    The following would be equivalent, if you felt more like using the actual month name (not sure why, but kinda cool):

    <cfquery name="qmonths" datasource"...">

         select  jid,date,...

         from tbl_jobs

         where monthname(date) = 'May'

    </cfquery>

    Of course, there are lot of different ways to achieve the same thing, so be sure to look through the array of functions that mySQL offers.

    Regards