Hey all,

I ran into this yesterday when theming a cck date field.

I can make date_format_date() work with long, medium, or short, but not mycustomformat.

I notice that mycustomformat is in the database table date_format_types, and the only difference between it and the other, default types, is that locked is set to 0.

Cleared cache, etc.

To replicate, create a custom format with a custom display format (why are these both called 'formats'? This should be changed). Create a field that uses another format for display. Now, attempt to use the custom display format in the following programmatic way:

  $date_raw = $field_date[0]['value']; //Get datestamp from cck field, could use $node->whatever
  $date_object = date_make_date($date_raw); //Format_date wants a date object, so create one
  $formatted_date = date_format_date($date_object,'mycustomtype'); 
  print $formatted_date;

Comments

rukaya’s picture

I think this is pretty similar to this issue http://drupal.org/node/677778, so apparently you just aren't meant to use date_format_date for this. I really want to know how to be able to format dates using a custom format which was defined through that admin interface too though, does anybody know how to do it?

Edit: this was logged as a bug in D7 http://drupal.org/node/826486 and has now been fixed, looks as if it's not possible to do for 6.x though. In the token module there's a patch to get a token for your custom date http://drupal.org/node/998156 but it's not been committed.

zeuty’s picture

You can use:

<?php
  print date_format_date($date_raw, 'custom', variable_get('mycustomtype', 'Y-m-d'));
?>
damienmckenna’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Unfortunately the Drupal 6 version of the Date module is no longer supported. That said, we appreciate that you took time to work on this issue. Should this request still be relevant for Drupal 7 please feel free to reopen it. Thank you.