5

I am constructing a content type that will 'wrap' a video, either youtube, vimeo or file upload. One of the fields required is a 'duration' field. Obviously a requirement is also for the videos to be sortable in a view based on that field.

How would I go about doing that? A format of H:i:s or i:s would be prefered in a textfield as an input method.

4 Answers 4

7

Posting my comment as answer - Check for HMS (Hours Minutes Seconds) Field module.

Displays a integer formatted as Hours, Minutes or Seconds. The field stores values as integer. Both input and output can be formatted as Hours, Minutes and/or Seconds. Alter functions provides developers a way to add their own format.

1

You can use the Date module. It will provide a cck date field, which you can configure as duration field

4
  • I've thought of that, but scemantically it's still a date. Is there a way to somehow get an actual duration type field?
    – user5005
    Commented Nov 27, 2012 at 11:36
  • Date and time field is good for a duration, However there is a time period module available, pls check that drupal.org/project/timeperiod also check drupal.org/project/interval Commented Nov 27, 2012 at 11:43
  • 2
    @AnoopJoseph mind if I add a module to that list ;) take a look at drupal.org/project/hms_field
    – AjitS
    Commented Nov 27, 2012 at 11:46
  • @indrock add your module as a reply so I can checkmark it :)
    – user5005
    Commented Nov 27, 2012 at 11:56
1

You can use format_interval():

return format_interval(strtotime("2009-07-06") - strtotime("2007-06-01"));
// 2 years 1 month
1

Also for Drupal 8 you can use - Duration field module

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.