Correct way for a db_query for nodes between two timestamps I have a very simple db_query.  I want to look for any node created between two timestamps.

This query works fine in MySQL shell

SELECT nid as id,created as start,title FROM node WHERE created BETWEEN '1403564400' AND '1403650800';


This works fine in Drupal

$data = db_query("SELECT nid as id,created as start,title FROM node")-&gt;fetchAll();
echo json_encode($data);


As soon as I add in the BETWEEN conditions below I get an Internal Server Error.

$data = db_query("SELECT nid as id,created as start,title FROM node WHERE created BETWEEN '1403564400' AND '1403650800'")-&gt;fetchAll();


I am unsure what I am doing wrong here, perhaps someone can point me in the right direction please!
You can try using db_select instead wich is a better way to create query with Drupal (assuming you are using Drupal 7).

$start_time = '1403564400';
$end_time = '1403650800';
$query = db_select('node', 'n')
  -&gt;fields('n', array('nid', 'created', 'title'))
  -&gt;condition('created', array($start_time, $end_time), 'BETWEEN');
$result = $query-&gt;execute();
$record = $result-&gt;fetchAll();