Jump to content


Photo

next birthday date


  • Please log in to reply
19 replies to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 21 September 2006 - 11:49 AM

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

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 21 September 2006 - 12:01 PM

<?php

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

?>

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 21 September 2006 - 12:04 PM

... i dont understand the code above, it just comes out with one. that isnt wat i want....



#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 21 September 2006 - 12:54 PM

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

well, since birthdays are always the same month and day every year, just try something like this:
<?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;
?>

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 21 September 2006 - 12:57 PM

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.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 21 September 2006 - 12:59 PM

i just want to know the date of someones next birthday, no logic, no todays birthdays, just that.

#7 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 21 September 2006 - 01:00 PM

what do u mean u thought all i have to do is show todays birthdays? why?

#8 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 21 September 2006 - 01:01 PM

Does it matter why he wants to show it? 

#9 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 21 September 2006 - 01:04 PM

that is my thoughts exactly, but didnt want to sound as if i was being rude.. lol

#10 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 21 September 2006 - 01:09 PM

Obsidian's method looks good

#11 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 21 September 2006 - 01:11 PM

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?


#12 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 21 September 2006 - 01:14 PM

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

#13 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 21 September 2006 - 01:15 PM

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.

#14 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 21 September 2006 - 01:16 PM

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.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#15 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 21 September 2006 - 01:17 PM

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.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#16 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 21 September 2006 - 01:18 PM

i aint mad! i never get mad! theres no point! i just dont have any specific reason for wanting it.

#17 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 21 September 2006 - 01:19 PM

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.


there are several reasons i can think of to show someone's next 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 upcoming 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 ???
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#18 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 21 September 2006 - 01:21 PM

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


#19 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 21 September 2006 - 01:29 PM

no problem... try this out:
<?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);
?>

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#20 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 21 September 2006 - 01:39 PM

thank you very much, exactly what i need




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users