Jump to content

Problems with having part of the date ignored


ClassicNancy

Recommended Posts

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 ****/

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.