Trying to Find Who's Birthday

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Noyb

    Trying to Find Who's Birthday

    I have a DATE field on a mysql db that stores users birthdays (the month
    and the day, the year doesn't matter). I am trying to have a query that
    returns the names of those whose birthdays are today. Currently I am
    returning everyones birthdays and then looping through them doing a
    string comparison. Can't I do this work in the query?

    Something like:
    $bday_qry="SELE CT user_fname, user_lname, user_bday
    FROM users
    WHERE DATE_FORMAT(use r_bday, %m-%d)==".date("m-d");

    What's the best way to do this?
    Thanks,
    Steve
  • Sharif T. Karim

    #2
    Re: Trying to Find Who's Birthday

    Noyb, being the foo Noyb is, wrote:[color=blue]
    > I have a DATE field on a mysql db that stores users birthdays (the
    > month and the day, the year doesn't matter). I am trying to have a
    > query that returns the names of those whose birthdays are today.
    > Currently I am returning everyones birthdays and then looping through
    > them doing a string comparison. Can't I do this work in the query?
    >
    > Something like:
    > $bday_qry="SELE CT user_fname, user_lname, user_bday
    > FROM users
    > WHERE DATE_FORMAT(use r_bday, %m-%d)==".date("m-d");
    >
    > What's the best way to do this?
    > Thanks,
    > Steve[/color]

    Sure, you can simple select the birthdays for the current day in the WHERE
    clause.
    $current_date = getdate(); //www.php.net/getdate for reference
    $bday_qry = "SELECT ";
    $bday_qry.= "user_fname , user_lname, DATE_FORMAT(use r_bday, '%m-%d') AS bday
    ";
    $bday_qry.= "WHERE "
    $bday_qry.= "MONTH(user_bda y) = '" . $current_date['mon'] . "' AND
    DAYOFMONTH(user _bday) = '" . $current_date['mday'] . "' AND YEAR(user_bday)
    = '" . $current_date['year'] . "'";

    That should do it I think =D.
    --
    Sharif T. Karim
    ....you don't know wrath yet...


    Comment

    • Noyb

      #3
      Re: Trying to Find Who's Birthday

      Sharif T. Karim wrote:[color=blue]
      > Noyb, being the foo Noyb is, wrote:
      >[color=green]
      >>I have a DATE field on a mysql db that stores users birthdays (the
      >>month and the day, the year doesn't matter). I am trying to have a
      >>query that returns the names of those whose birthdays are today.
      >>Currently I am returning everyones birthdays and then looping through
      >>them doing a string comparison. Can't I do this work in the query?
      >>
      >>Something like:
      >>$bday_qry="SE LECT user_fname, user_lname, user_bday
      >>FROM users
      >>WHERE DATE_FORMAT(use r_bday, %m-%d)==".date("m-d");
      >>
      >>What's the best way to do this?
      >>Thanks,
      >>Steve[/color]
      >
      >
      > Sure, you can simple select the birthdays for the current day in the WHERE
      > clause.
      > $current_date = getdate(); //www.php.net/getdate for reference
      > $bday_qry = "SELECT ";
      > $bday_qry.= "user_fname , user_lname, DATE_FORMAT(use r_bday, '%m-%d') AS bday
      > ";
      > $bday_qry.= "WHERE "
      > $bday_qry.= "MONTH(user_bda y) = '" . $current_date['mon'] . "' AND
      > DAYOFMONTH(user _bday) = '" . $current_date['mday'] . "' AND YEAR(user_bday)
      > = '" . $current_date['year'] . "'";
      >
      > That should do it I think =D.[/color]

      Thanks Sharif!

      Comment

      Working...