CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    106

    [RESOLVED] php mysql generating list of having birthday next x days

    I try to make a list of people that are having their birthdays for a certain period of time.
    I have the birthdate in a datefield in mysql, how can I get a resultset of people that will have birthday today and the next 6 days (or 7 or 8 etc) AND order them by date and not birthdate.
    I know it can be done by using a lot of code, but I guess it could be done in 1 or 2 lines of code.
    It has to work also if I want a list for the next 7 days when its 30 december or so, so ordering by just dateparts would not work in that case

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: php mysql generating list of having birthday next x days

    Use mktime() and add +7 to the day. Then it's a simple < query comparing the date in the future with the birthday column.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    106

    Re: php mysql generating list of having birthday next x days

    did not work.

    Dit some trying and asking and came with the following query :

    PHP Code:
    select pers_idpers_voornaampers_tussenvoegsel,pers_achternaampers_meisjesnaampers_plaatspers_gebdat, (unix_timestamp(date_format(pers_gebdat,'2011-%m-%d 00:00:00'))) as tijdstamp from personen where (unix_timestamp(date_format(pers_gebdat,'2011-%m-%d 00:00:00'))) between (unix_timestamp(date_format(curdate(),'2011-%m-%d 00:00:00'))) and (unix_timestamp(date_format((curdate()+interval 70 day),'2012-%m-%d 00:00:00'))) union select pers_idpers_voornaampers_tussenvoegsel,pers_achternaampers_meisjesnaampers_plaatspers_gebdat, (unix_timestamp(date_format(pers_gebdat,'2012-%m-%d 00:00:00'))) as tijdstamp from personen where (unix_timestamp(date_format(pers_gebdat,'2012-%m-%d 00:00:00'))) between (unix_timestamp(date_format(curdate(),'2011-%m-%d 00:00:00'))) and (unix_timestamp(date_format((curdate()+interval 70 day),'2012-%m-%d 00:00:00'))) order by tijdstamp 
    where I use the union in cases the enddate is the next year (set the interval to 70 days to check it) I use php to fill in the years

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: [RESOLVED] php mysql generating list of having birthday next x days

    Whoa...that is way too much. If what I said didn't work...it's because you didn't implement it correctly.

    PHP Code:
    <?php
    $sevenDaysOut 
    date('Y-m-d'mktime(000date('m'), date('d') + 7date('Y')));
    $query "SELECT FROM table WHERE date <= '" $sevenDaysOut "'";
    ?>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured