Jump to content

Archived

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

brown2005

next birthday date

Recommended Posts

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

Share this post


Link to post
Share on other sites
[code]<?php

$nums=explode("-",$birthdate);
$nums[0]++;
echo implode("-",$nums);

?>[/code]

Orio.

Share this post


Link to post
Share on other sites
[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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
hi obsidian,

if say i use 30-03-1983 it prints out 30-03-1984, cause it just adds 1 onto the date provided.

so what i think i need to do is work out the age of the person and use this and if it has gone this year add 1 to it or not leave as is....

ne ideas?

Share this post


Link to post
Share on other sites
If you go on www.php.net search mktime(); in functions
you will be told exactly how to set the same day, and month 1 year on..

Which as obsidian clearly stated above that method should work...

Share this post


Link to post
Share on other sites
yes but it is not 1 year on is it...

we are in 2006... my next birthday based on 30-03-1983 is

30-03-2007 not 30-03-1984.

Share this post


Link to post
Share on other sites
sorry if you all got so mad with me asking a quistion, but as a php programmer and a designer it's always nice to keep up with the times.

Share this post


Link to post
Share on other sites
you've got to use YYYY-MM-DD format like you showed in your first post. as for your last question about the age, i don't understand what you're asking.

Share this post


Link to post
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 ???

Share this post


Link to post
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...

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.