This post explains how to add a field representing the length of piece of music in minutes and seconds (eg. 35m 05s). Other may find it useful too.

  1. Ensure that CCK and the Date module are enabled.
  2. First, we define a new date format that displays as, for example, 05m 35s.
    • Go to Admin, and in the Site configuration section, select Date and time.
    • Click Formats, and then Add Format
    • In the Format string field, enter: i\m s\s (where "i" represents minutes, "s" seconds, and the \m and \s are suffixes)
      For a longer suffix, for example, enter: i\m\i\n s\s\e\c (\m\i\n = min and \s\e\c=sec)
      And click Save Configuration
    • If you click Custom Formats, you can see your new format listed
    • Click Configure
    • In the Add format type section, enter in the name field "Duration" and in the Type field, enter "duration" and click Save Configuration
    • Still on the Configuration tab, you'll see after the Long, Medium and Short date formats, your new format called "Duration". From the select box, you will be able to select your new date format, showing as, for example, 20m 35s (the actual number will depend on the current time)
    • Click Save Configuration
  3. Go to Content Types, and for the type you want to add a "duration" field, click Manage Fields.
    • In Add New field, enter a new field label (eg. duration), the field_ name, (eg. so it reads field_duration)
    • Select the field type of datetime, and from the select list, Text Field with custom input format
  4. On the new duration field configuration screen
    • In the Customize Default Value section, enter: 1 January 2000 0:0:0
      This sets a default common starting date and time, most of which will be ignore, but will ensure that if we want we sort this field
    • In the Custom input format field, enter: i:s
      Which requires the duration to be entered as: minutes : seconds
      If you wish, you could add to this field's Help text: Minutes : Seconds
    • In granularity, ensure that all are selected, including "seconds"
    • In Default Display, you should find your new date format available called "duration"
  5. And that's it, and the field should be available in Views too.

Comments

amitsedaiz’s picture

Great.... Thanks. Had been looking for a solution like this. Just a query... if my format is H:i , is there a possibility to add am or pm in the 12 hour format?

iantresman’s picture

Yes, the format is specified by the PHP date format, so to add am or pm, change the format string from "H:i" to "H:i a".