[development] DB Column Format

mark burdett mfburdett at gmail.com
Thu May 14 18:47:50 UTC 2009

On Thu, May 14, 2009 at 11:07 AM, Nancy Wichmann <nan_wich at bellsouth.net> wrote:
> Next question: Is there are Drupal or database-independent date formatting
> function that produces a DATETIME value. I know I can use date() with
> something appropriate, but I don’t know how efficient that is.

using PHP functions like gmdate() should always be more efficient,
because these functions (or, date_create() and date_format() in drupal
7) are what format_date() uses anyways. Multiple times in fact.. it's
a rather slow function if you benchmark it.

If you do use format_date() to put dates in the database make sure you
give it a time zone to use, otherwise you will end up with datetimes
in different time zones depending on the current user's configured
time zone.

> Would there be any interest in my submitting a patch for “format_date($time,
> ‘datetime’)?”

If this patch gets committed http://drupal.org/node/325827 then date()
function will also work in the current user's time zone, not the
server-wide time zone, so it wouldn't be useful for inserting dates in
the database or generating date-based URL path components that should
not vary depending on the current user's time zone.  I might be
interested in a helper function that generates dates in the site-wide
default time zone, otherwise developers will be doing this which is
pretty verbose for getting a date: format_date($timestamp, 'custom',
$format, variable_get('date_default_timezone',
date_default_timezone_get()), 'en')


More information about the development mailing list