Solved

MySQL Problem

Posted on 2010-09-11
2
392 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MVC - procedural PHP 10 35
Help With Simple Database Design 7 50
Need to remove %20 from url in get 17 36
check mysql insert 12 26
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

861 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