PHP/MySQL to ignore part of a date.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ClassicNancy
    New Member
    • Jun 2007
    • 8

    PHP/MySQL to ignore part of a date.

    I have this mod for my forum and it calls the birthdate from the database. I would like to have it not see the year. What is happening if a person puts a year in the box in their profile it makes it Dec 31st because that year is already over. There is no way to remove that box from the code according to the forum tech people. I've added the two pieces that refer to date. It already is written where it only shows the month and day in the display. Thank you to anyone that can help.


    [PHP]$birthdays = get_birthdays() ;
    if(!$birthdays) {
    $text = 'No birthdays yet';
    } else {
    $num = count($birthday s);

    $i = 1;

    foreach($birthd ays as $b) {
    $date = explode("-", $b["user_birth day"]);
    $user = get_user($b["user_id"]);
    $user_menus[] = create_user_pop up($user);
    if($date[2] == date('j')) {
    $text.= "<img src='" . BASE_DIR . "/birthday.gif' title=\"User's birthday today!\"/>";
    $dateprint = '<span style=\'color:r ed\'><strong>TO DAY!</strong></span>';
    } else {
    $dateprint = date('F jS', mktime(0, 0, 0, $date[1], $date[2], $date[0]));
    }
    $text .= user_link_code( $b["user_id"], $b["user_name"]);
    $text .= " (" . $dateprint . ")";
    if($num > $i) {
    $text .= ', ';
    }
    $i++;
    }

    } [/PHP]


    [PHP]/**** BEGIN BIRTHDAYS TODAY ****/
    function get_birthdays() {
    $result = db_query("SELEC T user_id, user_name, user_birthday FROM wowbb_users
    WHERE DAYOFMONTH(user _birthday) >= DAYOFMONTH(NOW( )) AND MONTH(user_birt hday) = MONTH(CURRENT_D ATE) AND DAYOFMONTH(user _birthday) < DAYOFMONTH(CURR ENT_DATE)+7
    ORDER BY DAYOFMONTH(user _birthday) ASC;");
    while($row = db_fetch_row($r esult)) {
    $birthdays[] = $row;
    }
    return $birthdays;
    }

    /**** END BIRTHDAYS TODAY ****/[/PHP]
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    #2
    never mind I was doing this is mysql

    nomad
    Last edited by pbmods; Jun 12 '07, 03:36 AM. Reason: Fixed (added closing QUOTE tag).

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Removed 'pretty please' from thread title.

      Comment

      • nomad
        Recognized Expert Contributor
        • Mar 2007
        • 664

        #4
        Hi Nancy:
        I was thinking about your problem. Not sure if this will work
        Could you create another class Called FormatDate.
        which would have something like this.

        <?php
        return "02d/%02d<br>";
        ?>

        This will get rid of the year.

        nomad

        or how about using the functon sprintf(),

        Comment

        Working...