English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

OBJECTIVE - I am trying to pull all entries from $dbTable that were entered between November 1, 2007 23:18:18 and December 8, 2007 23:18:18.

DECLARATIONS:
$dbTable = table name
date field info = `dAt` datetime NOT NULL default '0000-00-00 00:00:00'

FAILED ATTEMPT - it showed no errors, just didnt pull anything
$query = "SELECT * FROM $dbTable WHERE 'dAt' >= '2007-11-01 23:18:18' AND 'dAt' <= '2007-12-08 23:18:18'";

This worked, and displayed all dates, including dates in the range specified above.
$query = "SELECT * FROM $dbTable ORDER by 'dAt' DESC";

any ideas would be appreciated
thanks

2006-12-02 23:16:45 · 1 answers · asked by f1avor_f1av 3 in Computers & Internet Programming & Design

$i = 0;
$dbTable = "dAta";
$tabName = "dAt";
$start_time = "'2007-11-09 23:18:18'";
$end_time = "'2007-12-09 23:18:18'";
$query = "SELECT * FROM $dbTable WHERE $tabName BETWEEN $start_time AND $end_time ORDER BY DateTime DESC";

this just failed also, hehe

2006-12-02 23:45:59 · update #1

$dbTable = "dAta";
$tabName = "dAt";
$start_time = "'2007-11-09 23:18:18'";
$end_time = "'2007-12-09 23:18:18'";
$query = "SELECT * FROM $dbTable WHERE $tabName BETWEEN $start_time AND $end_time ORDER BY $tabName DESC"; Now that worked, forgive me ive been up all night. Ill still keep this open, hook somebody up with the points. maybee any other interesting things when searching DATETIME would be neat, have a good one

2006-12-02 23:51:35 · update #2

1 answers

remove the single quotes around 'dAt' ;)
SELECT * FROM $dbTable WHERE dAt >= '2007-11-01' AND dAt <= '2007-12-08'

Your query didn't yield any result because it tells mySql to look for entries where the string 'dAt' is bigger or the same as the string '2007-11-01...' ;) instead of comparing the string '2007-11-01..' with the COLUMN dAt :)

2006-12-03 05:42:56 · answer #1 · answered by Martin I 3 · 0 0

fedest.com, questions and answers