Jump to content

next birthday date


brown2005

Recommended Posts

[quote author=brown2005 link=topic=108907.msg438644#msg438644 date=1158839368]
if

$birthdate = "2006-03-30";

how can i write a function that will tell me when the next birthday is.

i.e. 30-03-2007....
[/quote]
well, since birthdays are always the same month and day every year, just try something like this:
[code]
<?php
// define birthday
$birthdate = "2006-03-30";

// split date up into pieces
list($year, $month, $day) = explode('-', $birthdate);

// create next birthday
$next = date('Y-m-d', mktime(0,0,0,$month,$day,$year + 1));
echo $next;
?>
[/code]

hope this helps
Link to comment
https://forums.phpfreaks.com/topic/21518-next-birthday-date/#findComment-96028
Share on other sites

[quote author=redarrow link=topic=108907.msg438681#msg438681 date=1158843426]
sorry but i dont understand your logic can you kindly tell me why you want to show next users birthdays i thort all you have to do is show todays birthdays.
[/quote]

there are several reasons i can think of to show someone's [b]next[/b] birthday. the most logical of which is a profile. if you're showing their birthday and it's already past this year, you want to show their [i]upcoming[/i] birthday. as for, "keeping up with the times", as you put it, i fail to see what relevance that has on understanding WHY he's wanting to do what he's doing ???
Link to comment
https://forums.phpfreaks.com/topic/21518-next-birthday-date/#findComment-96055
Share on other sites

rite

the script u have written obisidan adds 1 to the year so my birthday

1983-03-30

with your script is

1984-03-30

wat i want is not 1 year after my birthday, i want the next birthday as u have stated, but from the birthdate, not the date of this year 2006-03-30 as i think you think i mean...
Link to comment
https://forums.phpfreaks.com/topic/21518-next-birthday-date/#findComment-96057
Share on other sites

no problem... try this out:
[code]
<?php
function getNextBDay($bday) {
  list($bd_year, $bd_month, $bd_day) = explode('-', $bday);
  $today = date('Y-m-d');
  list($td_year, $td_month, $td_day) = explode('-', $today);
 
  // get your birthday of this year in timestamp
  $thisBday = mktime(0,0,0,$bd_month, $bd_day, $td_year);
  if ($thisBday < mktime(0,0,0,$td_month, $td_day, $td_year)) {
    // birthday has passed, so increment the year
    $thisBday = mktime(0,0,0,$bd_month, $bd_day, $td_year + 1);
  }

  return date('Y-m-d', $thisBday);
}

$birthday = "1983-03-30";
echo getNextBDay($birthday);
?>
[/code]

hope this helps
Link to comment
https://forums.phpfreaks.com/topic/21518-next-birthday-date/#findComment-96068
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.