Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Thursday, 8 September 2011

[SOLVED] Drupal db_query and date formats

Here's small issue I came across and didn't find many answers online. When using Drupal's db_query method to execute some SQL that contains dateformats in it the weekday always comes out as a zero.
for example:

db_query("SELECT DATE_FORMAT(from_unixtime(changed), '%Y-%m-%d') lastmod FROM node LIMIT 10");

This will return dates like 2011-09-0. The month day will always be zero. It will also match %s (seconds), %f (microseconds), and %b (abbreviated month name) Don't worry there's a simple solution.