How to write a db_query with condition on a datefield with enddate - value1 and value2 Trying to do following select query on a node with datefield with endvalue:

  SELECT nid FROM {node}
  WHERE uid = $uid
  AND type = $type
  AND field_mytime(value) &gt; $daystart
  AND field_mytime(value2) &lt; $dayend;


  db_query('SELECT nid FROM {node}
     WHERE uid = :uid AND type = :type AND field_mytime['und'][0]['value'] &gt; :value, field_time['und'] [0]['value2'] &lt; :value2',
    array(':uid' =&gt; $u, ':type' =&gt; 'mycontenttype', ':value' =&gt; $daystart, ':value2' =&gt; $dayend))-&gt;fetchField();


This do not work of cource: 
  field_mytime['und'][0]['value']
  field_mytime['und'][0]['value2']

But what will work? Please help.
Fields are not stored in the node/entity table to which they relate, it would be quite inefficient to do that.

Drupal 7 introduced the new EntityFieldQuery class to help you build up these kinds of queries. I'd recommend reading the docs, but for your purposes the code would look something like this:

$query = new EntityFieldQuery;
$query-&gt;entityCondition('entity_type', 'node')
  -&gt;entityCondition('bundle', $type)
  -&gt;propertyCondition('uid', $uid)
  -&gt;fieldCondition('field_mytime', 'value', $daystart, '&gt;')
  -&gt;fieldCondition('field_mytime', 'value2', $dayend, '&lt;');

$results = $query-&gt;execute();
if (isset($results['node'])) {
  // Load all node objects based on the results of the query
  $nids = array_keys($results['node']);
  $nodes = node_load_multiple($nids);
}