brown2005 Posted September 21, 2006 Share Posted September 21, 2006 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 Link to comment Share on other sites More sharing options...
Orio Posted September 21, 2006 Share Posted September 21, 2006 [code]<?php$nums=explode("-",$birthdate);$nums[0]++;echo implode("-",$nums);?>[/code]Orio. Quote Link to comment Share on other sites More sharing options...
brown2005 Posted September 21, 2006 Author Share Posted September 21, 2006 ... i dont understand the code above, it just comes out with one. that isnt wat i want.... Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 21, 2006 Share Posted September 21, 2006 [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 pieceslist($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 Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 21, 2006 Share Posted September 21, 2006 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 Link to comment Share on other sites More sharing options...
brown2005 Posted September 21, 2006 Author Share Posted September 21, 2006 i just want to know the date of someones next birthday, no logic, no todays birthdays, just that. Quote Link to comment Share on other sites More sharing options...
brown2005 Posted September 21, 2006 Author Share Posted September 21, 2006 what do u mean u thought all i have to do is show todays birthdays? why? Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 21, 2006 Share Posted September 21, 2006 Does it matter why he wants to show it? Quote Link to comment Share on other sites More sharing options...
brown2005 Posted September 21, 2006 Author Share Posted September 21, 2006 that is my thoughts exactly, but didnt want to sound as if i was being rude.. lol Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 21, 2006 Share Posted September 21, 2006 Obsidian's method looks good Quote Link to comment Share on other sites More sharing options...
brown2005 Posted September 21, 2006 Author Share Posted September 21, 2006 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? Quote Link to comment Share on other sites More sharing options...
xyn Posted September 21, 2006 Share Posted September 21, 2006 If you go on www.php.net search mktime(); in functionsyou 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... Quote Link to comment Share on other sites More sharing options...
brown2005 Posted September 21, 2006 Author Share Posted September 21, 2006 yes but it is not 1 year on is it...we are in 2006... my next birthday based on 30-03-1983 is30-03-2007 not 30-03-1984. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 21, 2006 Share Posted September 21, 2006 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. Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 21, 2006 Share Posted September 21, 2006 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. Quote Link to comment Share on other sites More sharing options...
brown2005 Posted September 21, 2006 Author Share Posted September 21, 2006 i aint mad! i never get mad! theres no point! i just dont have any specific reason for wanting it. Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 21, 2006 Share Posted September 21, 2006 [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 ??? Quote Link to comment Share on other sites More sharing options...
brown2005 Posted September 21, 2006 Author Share Posted September 21, 2006 ritethe script u have written obisidan adds 1 to the year so my birthday1983-03-30with your script is1984-03-30wat 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... Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 21, 2006 Share Posted September 21, 2006 no problem... try this out:[code]<?phpfunction 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 Quote Link to comment Share on other sites More sharing options...
brown2005 Posted September 21, 2006 Author Share Posted September 21, 2006 thank you very much, exactly what i need Quote Link to comment 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.