Jump to content

[SOLVED] SQL query problem


ferret147

Recommended Posts

I am using Dreamweaver to make a On This Day scrips, I already have a database populated but just having a slight problem getting the info I want displayed.

 

In the database I have a date field for each record formatted like this yyyy-mm-dd, when the year changes I have to go through the entire database and change it from say for this year 2008 to 2009 to get my records to display, so I am trying to give the year a wild card so if any entrys match the month and day they will display instead this will save me loads of time every year going through the database and changing the year.

 

Below is the code I have so far but all it displays is the first entry in the database.  Can anybody please advise as to where I am going wrong or even if I am going in the right direction for this.

 

 

$today = date("%%%%-m-d");


$query_Recordset1 = sprintf("SELECT * FROM OnThisDay WHERE `date` = '$today'", $colname_Recordset1);

Link to comment
https://forums.phpfreaks.com/topic/148216-solved-sql-query-problem/
Share on other sites

SELECT * FROM OnThisDay WHERE MONTH(`date`) = MONTH(CURDATE()) AND DAY(`date`) = DAY(CURDATE())

 

or

 

SELECT * FROM OnThisDay WHERE DATE_FORMAT(`date`,'%e-%m') = DATE_FORMAT(CURDATE(),'%e-%m')

 

or... there are possibly dozens other ways to do this ;)

 

See http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.