Solved

MySQL Problem

Posted on 2010-09-11
2
393 Views
Last Modified: 2012-05-10
In a solution provided in a previous question I was given this:

$rd = $_REQUEST['start_date'];
$sql = "SELECT * FROM `listings` WHERE `date` >= date_add(str_to_date('$rd', '%d/%M/%Y'), interval -3 day) and `date` < date_add(str_to_date('$rd', '%d/%M/%Y'), interval 4 day) ";

I need to know if this would work:


$rd = $_REQUEST['start_date'];
$sql = "SELECT * FROM `listings` WHERE str_to_date(`date`, '%d/%M/%Y') >= date_add(str_to_date('$rd', '%d/%M/%Y'), interval -3 day) and str_to_date(`date`, '%d/%M/%Y') < date_add(str_to_date('$rd', '%d/%M/%Y'), interval 4 day) ";

0
Comment
Question by:grantunwin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 33653363
Only if the column `date`contains not date data, but VARCHAR data in d/M/Y format.
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33653370
Using any function on the `date` column also causes an index on that column to be unusable.  Consider making a date range that will cover the date+time involved.
If `date` contains time data and you want to include the 7th day, then try this

$rd = $_REQUEST['start_date'];
$sql = "SELECT * FROM `listings` WHERE `date` >= date_add(str_to_date('$rd', '%d/%M/%Y'), interval -3 day) and `date` < date_add(str_to_date('$rd', '%d/%M/%Y'), interval 5 day) ";

< ".. interval 5 days "

will include any hour on the day "$rd +4 days"
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question