0

My Drupal offers only three types of rendering a Date ISO field (Display management in Content Type admin panel). What if I want to see my date in a different way? Is there any way to set my own formatter?

Second question. Is there any possibility to indicate while calling render(...) or field_view_value(...) (or anywhere else) what formatter to use? For example, I want for specific set of nodes to show not brief date variant but a full one. How can it be achieved?

1

There are two thing to do for the date format:

First create a date format (admin/config/regional/date-time/formats/add): this where you define how the date will be display and a simple PHP string date format is all you need something like 'm/d/Y' will show the date as 08/20/2012.

Once the date format is added you can use it on any "Date Type" (admin/config/regional/date-time) or you can create your own date type and assign the date format to it.

To display different date formats depending on what view of node is you have multiple options:

  1. Use panels, views, context or display suite and format the date to your date type or date format

  2. Edit or create a template for your node type (node--CONTENT-TYPE.tpl.php if D7 or node-CONTENT-TYPE.tpl.php if D6) and use the format_date function to format it.

    if ($teaser) { format_date($node->created, 'custom', 'Y-m-d H:i O')); } else { format_date($node->created, 'custom', 'H:i O Y-m-d')); }

OR using your date type:

if ($teaser) {
format_date($node->created, 'DATE-TYPE'));
} else {
format_date($node->created, 'DATE-TYPE'));
}
| improve this answer | |
  • This not an answer to my question, because it was in essence about field rendering and on top of everything unfortunately format_date worls with UNIX timestamps whereas Date (ISO) module stores values in varchar format. But still many thanks for your efforts=) – DimG Aug 23 '12 at 13:27
0

Solved that!

in admin/config/regional/date-time there is an ability to add "date type" (there are three default ones, brief, medium ad full format) as well as to add custom format pattern in PHP date()-style for any "date type". Sweet!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.