944,141 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 4444
  • PHP RSS
Apr 2nd, 2007
0

query get upcoming birthdays

Expand Post »
after some searching I come up with the below which give the error I posted. I'm surprised that I have not been able to find script that uses mysql to get birthdays within x days.

error message, any ideas, thank you for the help
SQL Error: SELECT DOB, STR_TO_DATE(CONCAT(EXTRACT(DAY FROM DOB),'-',EXTRACT(MONTH FROM DOB),'-',EXTRACT(YEAR FROM CURDATE())),'%y-%m-%d') AS ThisYearsDate FROM users WHERE CURDATE() BETWEEN 'ThisYearsDate'
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

[php]
$query_get_member_bdays = ("SELECT DOB, STR_TO_DATE(CONCAT(EXTRACT(DAY FROM DOB),'-',EXTRACT(MONTH FROM DOB),'-',EXTRACT(YEAR FROM CURDATE())),'%y-%m-%d') AS ThisYearsDate FROM users WHERE CURDATE() BETWEEN 'ThisYearsDate'");
[/php]
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
proctk is offline Offline
2 posts
since Jun 2006
Apr 5th, 2007
0

Re: query get upcoming birthdays

Click to Expand / Collapse  Quote originally posted by proctk ...
after some searching I come up with the below which give the error I posted. I'm surprised that I have not been able to find script that uses mysql to get birthdays within x days.

error message, any ideas, thank you for the help
SQL Error: SELECT DOB, STR_TO_DATE(CONCAT(EXTRACT(DAY FROM DOB),'-',EXTRACT(MONTH FROM DOB),'-',EXTRACT(YEAR FROM CURDATE())),'%y-%m-%d') AS ThisYearsDate FROM users WHERE CURDATE() BETWEEN 'ThisYearsDate'
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

[php]
$query_get_member_bdays = ("SELECT DOB, STR_TO_DATE(CONCAT(EXTRACT(DAY FROM DOB),'-',EXTRACT(MONTH FROM DOB),'-',EXTRACT(YEAR FROM CURDATE())),'%y-%m-%d') AS ThisYearsDate FROM users WHERE CURDATE() BETWEEN 'ThisYearsDate'");
[/php]

There are a lot of php scripts that do this, however they are not standalone since they work on the database listing user data for some other system. For example, this forum should have an extension/module that will show upcoming users birthdays.

If you want to look through the codes for one of these pick a well used open source forum or CMS and search their module repository for an upcoming birthdays module.

For your mysql query there is only one value for the BETWEEN operator when there should be 2 values for comparison.

eg:

[HTML]"between min and max"[/HTML]

Heres the correct syntax:

http://dev.mysql.com/doc/refman/5.0/...nction_between

The above also has an explanation for how to use this with dates.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Apr 5th, 2007
0

Re: query get upcoming birthdays

Yeah I agree with digital, you should change the where clause to WHERE DOB BETWEEN CURDATE() AND CURDATE()+7

I think mysql can do that if not just use DATE_ADD()

I also think that you have over complicated the SELECT part using STR_TO_DATE() all you need to do is return the DOB and the age of the person which you can do with DATEDIFF() and if you need to change the date format use DATE_FORMAT.
Reputation Points: 10
Solved Threads: 4
Light Poster
UrbanSky is offline Offline
42 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Best news / article script ?
Next Thread in PHP Forum Timeline: updating user field not working, help??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC