How do I retrieve a DateTime column from my MySQL database using Drupal Database API + PHP. The DateTime format is in YYYY-MM-DD HH:MM:SS(2013-02-20 23:59:59). I want to retrieve all the rows in the database that match a specific date, and then store the hour inside an array.

For example, I want to grab all the data from January 1, 2013. I then only want to store hours 00:00 to 23:59 inside my array, not the entire date.

I do not want to use any modules to accomplish this.. because I need to code it inside my custom module.

Thanks for your help!

Current Code:

$query = db_select('Project', 'p');
$query-&gt;fields('p', array('submissions', 'date_time'));
$query-&gt;condition('p.user_id', $user-&gt;uid);
$results = $query-&gt;execute()-&gt;fetchAll();
foreach($results as $r) {
    $rows[] = array(strtotime(date("H:i:s", $r-&gt;date_time))*1000, $r-&gt;submissions);
}


I plan to display the data on my Flot line graph.


Question: How do I prevent unwanted routing errors in production
Answer: You can redirect the user to the desire page you want if no route matchs

Write down the following code at the bottom of your routes.rb file

In /config/routes.rb

#If no route matches
match ":url" =&gt; "application#redirect_user", :constraints =&gt; { :url =&gt; /.*/ }


Then redirect the user to the error page in the application_controller.rb file

*In /app/controllers/application_controller.rb*

def redirect_user
  redirect_to '/404'
end