ClassicNancy Posted June 11, 2007 Share Posted June 11, 2007 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 view. Thank you to anyone that can help. $birthdays = get_birthdays(); if(!$birthdays) { $text = 'No birthdays yet'; } else { $num = count($birthdays); $i = 1; foreach($birthdays as $b) { $date = explode("-", $b["user_birthday"]); $user = get_user($b["user_id"]); $user_menus[] = create_user_popup($user); if($date[2] == date('j')) { $text.= "<img src='" . BASE_DIR . "/birthday.gif' title=\"User's birthday today!\"/>"; $dateprint = '<span style=\'color:red\'><strong>TODAY!</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++; } } /**** BEGIN BIRTHDAYS TODAY ****/ function get_birthdays() { $result = db_query("SELECT user_id, user_name, user_birthday FROM wowbb_users WHERE DAYOFMONTH(user_birthday) >= DAYOFMONTH(NOW()) AND MONTH(user_birthday) = MONTH(CURRENT_DATE) AND DAYOFMONTH(user_birthday) < DAYOFMONTH(CURRENT_DATE)+7 ORDER BY DAYOFMONTH(user_birthday) ASC;"); while($row = db_fetch_row($result)) { $birthdays[] = $row; } return $birthdays; } /**** END BIRTHDAYS TODAY ****/ Quote Link to comment https://forums.phpfreaks.com/topic/55163-problems-with-having-part-of-the-date-ignored/ Share on other sites More sharing options...
Wildbug Posted June 11, 2007 Share Posted June 11, 2007 I would like to have it not see the year. What do you mean by "it"? What dates are you trying to retrieve from the database? Not just the current day's birthdays, right? Please elucidate a bit more. Quote Link to comment https://forums.phpfreaks.com/topic/55163-problems-with-having-part-of-the-date-ignored/#findComment-272715 Share on other sites More sharing options...
ClassicNancy Posted June 11, 2007 Author Share Posted June 11, 2007 Hi...by it I mean this coding. I didn't write it a friend did and it works great except he didn't know how to get it to ignore the year in the birthday in the profile. He fixed so it does not display the year but if the profile states a year it says oh that year is over and it makes them all December 31st. Right now it looks for todays birthdays +7 days. Quote Link to comment https://forums.phpfreaks.com/topic/55163-problems-with-having-part-of-the-date-ignored/#findComment-272724 Share on other sites More sharing options...
bubblegum.anarchy Posted June 12, 2007 Share Posted June 12, 2007 Right now it looks for todays birthdays +7 days. And what do you want? Quote Link to comment https://forums.phpfreaks.com/topic/55163-problems-with-having-part-of-the-date-ignored/#findComment-272876 Share on other sites More sharing options...
ClassicNancy Posted June 12, 2007 Author Share Posted June 12, 2007 Hi...I don't want it to read the year in the profile code. Quote Link to comment https://forums.phpfreaks.com/topic/55163-problems-with-having-part-of-the-date-ignored/#findComment-272892 Share on other sites More sharing options...
bubblegum.anarchy Posted June 12, 2007 Share Posted June 12, 2007 Where does it read the year in the profile code? Do you want the get_birthdays() function to return a list of stored birthdays irrespective of the birthday year? Quote Link to comment https://forums.phpfreaks.com/topic/55163-problems-with-having-part-of-the-date-ignored/#findComment-272902 Share on other sites More sharing options...
ClassicNancy Posted June 12, 2007 Author Share Posted June 12, 2007 Yes...what this mod does is show todays birthdays and the next 7 days...I just want it to pull by month and day and ignore the year. It already displays that way but it reads the year also and makes anyone who has the year in their birthday be December 31 because that year is over. Quote Link to comment https://forums.phpfreaks.com/topic/55163-problems-with-having-part-of-the-date-ignored/#findComment-272905 Share on other sites More sharing options...
ClassicNancy Posted June 12, 2007 Author Share Posted June 12, 2007 I think it is pulling from here. foreach ($birthdays as $birthday => $birthday_list) $events["$birthday 00:00|$birthday"] = array( "event_id" => $birthday, "event_title" => count($birthday_list), "event_start" => "YYYY-MM-DD 00:00", "event_end" => "YYYY-MM-DD 00:00", "event_recurrence" => 1, "event_recurrence_settings" => "1|y|||", "event_public" => 1, "event_note" => $birthday_list); return $events; Quote Link to comment https://forums.phpfreaks.com/topic/55163-problems-with-having-part-of-the-date-ignored/#findComment-272914 Share on other sites More sharing options...
bubblegum.anarchy Posted June 12, 2007 Share Posted June 12, 2007 This following query might help guide you in the right direction: SELECT user_name , user_birthday , CURRENT_DATE , IF (date_format(user_birthday, concat(year(CURRENT_DATE), '-%m-%d')) >= CURRENT_DATE , date_format(user_birthday, concat(year(CURRENT_DATE), '-%m-%d')) , date_format(user_birthday, concat(year(CURRENT_DATE + INTERVAL 1 YEAR), '-%m-%d'))) AS next_birthday FROM wowbb_users ORDER BY next_birthday The above query lists all the user names, the current date and the users upcoming birthday date, there is just a matter of adding an appropriate WHERE clause to limit the records where the next_birthday is within a week. Quote Link to comment https://forums.phpfreaks.com/topic/55163-problems-with-having-part-of-the-date-ignored/#findComment-272922 Share on other sites More sharing options...
ClassicNancy Posted June 12, 2007 Author Share Posted June 12, 2007 Thank you. I'll check it out. Quote Link to comment https://forums.phpfreaks.com/topic/55163-problems-with-having-part-of-the-date-ignored/#findComment-272928 Share on other sites More sharing options...
Wildbug Posted June 12, 2007 Share Posted June 12, 2007 <?php $query = <<<EOQ SELECT user_id, user_name, DATE_FORMAT(user_birthday,'%M %D') AS birthday, DAY(user_birthday)=DAY(NOW()) AS is_today FROM wowbb_users WHERE (MONTH(user_birthday) = MONTH(NOW()) OR MONTH(user_birthday) = MONTH(NOW()) + 1 OR MONTH(user_birthday)=1 AND MONTH(NOW())=12) AND DAY(user_birthday) + IF( MONTH(user_birthday)=MONTH(NOW())+1 OR MONTH(user_birthday)=1 AND MONTH(NOW())=12, DAY(LAST_DAY(NOW())), 0 ) - DAY(NOW()) BETWEEN 0 AND 7 ORDER BY DAY(user_birthday) + IF( MONTH(user_birthday)=MONTH(NOW())+1 OR MONTH(user_birthday)=1 AND MONTH(NOW())=12, DAY(LAST_DAY(NOW())), 0 ) - DAY(NOW()) EOQ; $result = mysql_query($query); if ($result && mysql_num_rows($result)) { $text = array(); while ($birthday = mysql_fetch_assoc($result)) { $user = get_user($birthday['user_id']); $user_menus[] = create_user_popup($user); $text[] = ($birthday['is_today'] ? '<img src="'.BASE_DIR.'/birthday.gif" title="User\'s birthday today!"/>' : '') . user_link_code($birthday['user_id'], $birthday['user_name']) . ' (' . ($birthday['is_today'] ? '<span style="color:red"><strong>TODAY!</strong></span>' : $birthday['birthday']) . ')'; } $text = implode(', ',$text); // or echo implode(', ',$text) if outputting directly. } ?> I haven't tested the PHP, but the MySQL query seems to work well, including at month's/year's end and leap years. Quote Link to comment https://forums.phpfreaks.com/topic/55163-problems-with-having-part-of-the-date-ignored/#findComment-273169 Share on other sites More sharing options...
ClassicNancy Posted June 12, 2007 Author Share Posted June 12, 2007 Ok thank you. I'll check this too. Quote Link to comment https://forums.phpfreaks.com/topic/55163-problems-with-having-part-of-the-date-ignored/#findComment-273186 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.