Reply to comment

The main function in drupal to format a date is the format_date function which will take the formatting and timezone conversion you configured at http://yoursite/admin/settings/date-time and http://yoursite/admin/settings/date-time/formats

<?php
//format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL)
//An example convert the unix timestamp for now 
format_date(time(), 'medium''''Europe/Brussels');
?>

For more : http://api.drupal.org/api/function/format_date/6

When working with http://drupal.org/project/date and you have something like this stored into the database:

2010-06-11T14:00:00

You ll need to convert the stored format to a unix timestamp

<?php
//date_convert($date, $from_type, $to_type, $tz = 'UTC')
$timestamp date_convert($node->field_date[0]['value'], DATE_ISODATE_UNIX);
format_date($timestamp);

//When you try to do this you will NOT have the correct timestamp, it will not not take into account the timezone. So following is wrong
$timestamp strtotime($node->field_date[0]['value']);
?>

More on formats in the date.api.inc file or date_convert function.

Why is this all important? When moving code from one server to another located in different timezones the times displayed on your site not using the correct formatting functions may change. This may not seem to have a big impact when your just displaying dates. But when logic depends on it, let us say you only can register for this test until date x, it can cause the page to be in accesible too soon or too late.

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><img><p><b><i><table><th><tr><td><blockquote><br /><img /><tbody><span><strike>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <codes>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.