-
November 11th, 2011, 05:12 AM
#1
[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
-
November 11th, 2011, 03:12 PM
#2
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.
-
November 15th, 2011, 05:49 AM
#3
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_id, pers_voornaam, pers_tussenvoegsel,pers_achternaam, pers_meisjesnaam, pers_plaats, pers_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_id, pers_voornaam, pers_tussenvoegsel,pers_achternaam, pers_meisjesnaam, pers_plaats, pers_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
-
November 15th, 2011, 02:31 PM
#4
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(0, 0, 0, date('m'), date('d') + 7, date('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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|