Jump to content

between date help


dadamssg

Recommended Posts

i'm sure BETWEEN would work. i don't know the correct syntax to use though. I'm now familiar with querying with dates.

 

i have something like the following but its not workin...


$date = "2010-11-25";

$query = "SELECT * FROM `Events` WHERE date('2010-11-08') BETWEEN start AND end";


Link to comment
https://forums.phpfreaks.com/topic/218548-between-date-help/#findComment-1133880
Share on other sites

i'm sure BETWEEN would work. i don't know the correct syntax to use though. I'm now familiar with querying with dates.

 

i have something like the following but its not workin...


$date = "2010-11-25";

$query = "SELECT * FROM `Events` WHERE date('2010-11-08') BETWEEN start AND end";


 

That looks good (if start and end are column names in your table and are defined as DATE or DATETIME). Note that the $date (PHP) variable is not being used and is not the same value as you put in the query.

 

You could add code to print mysql_error() if the query fails so you can see why

 

$date = "2010-11-25";
$query = "SELECT * FROM `Events` WHERE date('$date') BETWEEN start AND end";
$result = mysql_query($query);
if ($result === false) {
  printf("Query Failed:\n%s\nError: %s\n", $query, mysql_error());
} else {
  // Looks Good, move on

 

 

Link to comment
https://forums.phpfreaks.com/topic/218548-between-date-help/#findComment-1133912
Share on other sites

yes they are fields in my database that are datetimes. The query won't return events that start and end on the same day though, which is what i also want. So this query isn't what i'm looking for...

 

$date = "'2010-11-03 00:00:00";

$query = "SELECT * FROM Events WHERE DATE('$date') BETWEEN start AND end ORDER BY start ASC";


Link to comment
https://forums.phpfreaks.com/topic/218548-between-date-help/#findComment-1133933
Share on other sites

BETWEEN is inclusive.

 

Is there some reason you have the time included as part of the start/end values?

 

Assuming the $date value is just a date -

 

SELECT * FROM Events WHERE '$date' BETWEEN date(start) AND date(end)

 

^^^ If that doesn't work, I recommend that you post a sample of your data, a $date value, and what the expected results should be.

Link to comment
https://forums.phpfreaks.com/topic/218548-between-date-help/#findComment-1133936
Share on other sites

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.