The Date module currently supports the following formats when it is used as a field in Views:

  • Default
  • As Time Ago
  • Long
  • Medium
  • Short

...would it be possible to create another option for "Custom" which allows a user to enter a PHP date format string such as "m/d/Y g:ia" etc.?

The Event module has this feature when you use the following patch discussed in: http://drupal.org/node/293894#comment-1011549 which is incredibly useful.

I found that I can grab multiple fields, format them, remove them from display and use the "Rewrite the output of this field" feature to create very useful views which read more like "April 2 3:30–5:30pm" in one column instead of something like "April 2, 2009 3:00pm" and "April 2, 2009 5:30pm" in separate columns.

Although unfortunately, development on a Drupal 6 version of Event seems to be dragging. Though, if you placed this functionality for PHP date format strings into the Views functionality for Date, I could ditch Event entirely.

Thanks in advance for your consideration of this idea.

CommentFileSizeAuthor
#10 dateformats.png61.91 KBvthirteen
#10 views_dateformats.png69.94 KBvthirteen

Comments

karens’s picture

Status: Active » Fixed

You can create as many custom format types as you like and they all will be available as options. You create them on the system date-time page (admin/settings-date-time, I think is the url). This change was made to make it easier to create locale-specific versions of all the date formats.

zooney’s picture

Gosh. I hadn't the slightest idea you could do that in Drupal. Woo-hoo! Thanks. =)

karens’s picture

It's not Drupal core doing this, it's done by Date API and Date Locale due to a great patch by stella and a bunch of folks at Civic Actions. We hope to get it into Drupal core in D7.

whatleyd’s picture

Thank you so much for this information. It is so timely. I am working with the calendar module as we speak.

I had to reply. The exact location to add your own format type

Administer | Site configuration | Date and time | Formats | Add format type

Here is the PHP: date - Manual http://us3.php.net/date

Thank you again for this timely question and answer.

jboeger’s picture

Hello and thanks for this thread. Can somebody help me with the string?

when creating a new custom format, I just want to show the time (which is: g).

How do I put that in the string?

ie.
string date ( string $g [, int $timestamp ] )

becomes....

??

Thanks in advance. (sorry just don't know php well at all...)

zooney’s picture

jboeger, essentially you have to do this:

1.) Install the proper modules, (Duh =D).
2.) Go to Administer->Site Configuration->Date and Time->Formats
3.) Go to Add Format and create your new PHP formatted date string (this will now show up in Custom Formats where you can remove any formats you make)
4.) Go to Configure and add a new format type.
5.) Select your format from step 3 in the dropdown under the new type.

...and your new format type will show up in dropdowns, etc.

...very cool. Thanks to all the people who worked on this stuff!

jboeger’s picture

Thanks Zooney. I understand all of that... I'm just having problems with the PHP string itself.

Any chance you can write me a string for just showing the time of day? ie 9:45am

zooney’s picture

...oh. =)

That'd just be "g:ia".

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

vthirteen’s picture

StatusFileSize
new69.94 KB
new61.91 KB

i created a new custom date format but it doesn't show up in views as a date format for fields. the only formats available are the default long, medium, short, plus various "time ago" aoptions and custom (which doesn't fit my needs because the internationalization module does not take care of it).

anything i'm doing wrong?

arlinsandbulte’s picture

@vthirteen:
Try clearing the cache.

scrofula’s picture

I have the same problem and clearing the views cache did not cause the custom formats to appear.

mcpuddin’s picture

I had the same issue as #10, and clearing the cache fixed the issue for me.

Anonymous’s picture

Version: 6.x-2.1 » 6.x-2.6
Category: feature » bug
Status: Closed (fixed) » Active

I'm using 6.x-2.6 and am coming across this problem where the custom date formats I've created aren't appearing in views. I've tried clearing the Views Cache, tried clearing the Drupal caches.

Also tried re-saving the content type settings (even though the View in this case is for Users and not Nodes), as well as removing content_type_info:en from cache_content table as per http://drupal.org/node/277077#comment-3346190.

(I don't know if this makes a difference but the date field I'm trying to format is an organic groups membership creation date.)

My cache_views_data table is empty and the cache_views table has 20-something rows. Do I need to manually do something to that table perhaps?

I'm fairly certain I'm using the latest versions of everything, so I really don't know what else to try.

milesw’s picture

Component: Date CCK Field » Code

I'm seeing the same issue with 6.x-2.6, trying to format the standard "Post Date" field. Only the core date formats are appearing. Tried clearing every possible cache, re-saving the content type.

milesw’s picture

Well, I just dug through the code for Views and Date, and didn't find anything indicating that custom formats *should* even appear on this list. The list of format options comes from Views in views_handler_field_date.inc, and I see nothing in the Date module that affects these options.

LarsKramer’s picture

Title: Add "Custom" format for Date fields in Views module » Custom format types are not available in Views
Version: 6.x-2.6 » 6.x-2.x-dev
Issue summary: View changes

Steps to reproduce:

  1. Create a custom date format at "yoursite.com/admin/settings/date-time/formats/add".
  2. Add the format to a format type.
  3. Create a view of nodes with fields
  4. Add a field "Node: post date".

The new format type is not shown on the list.

LarsKramer’s picture

Status: Active » Closed (duplicate)