Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Drupal 7 Interval Field module

Parent Feed: 

The Drupal 7 Interval Field module provides a simple way to create a duration or interval field on any Drupal 7 field-able entity. A common use for this might be on a content type that generally keeps track of dates. Sometimes it easier to summarize a group of dates to a user or visitor using an interval field rather than selecting multiple dates.

An interval field is useful for keeping track of data such as:

  • 5 hours
  • 33 seconds
  • 7 days
  • 3 months

Installing and configuring the module could not get any easier. To see it in action, simply install it like you would any other Drupal 7 module, and make sure to enable it on your module administration page. Now when you go to add a field to a content type, user, comment, or any other field-able entity, you will be able to create an Interval field.

When configuring the interval field, you can reduce the options presented to the user when an interval is created. For example, you can limit the options to only show the users "days" and "months" rather than allowing them to select from all of the interval options.

Really a simple module that can be useful. It really works best to provide a simplified way to store an interval, but also a user friendly way to present the data to a website visitor.

Hello everyone and welcome to another Daily Dose of Drupal. I am Shane Thomas, you can follow me on Twitter at smthomas3, also make sure to check codekarate.com, learn a little bit about our Drupal Commerce Course and our 5 Secrets EBook. We are on Episode Number 193 today and it’s going to be a short one and we’re going to be looking at the Interval Field Module. If you ever had a situation where you need to allow a field to show basically a duration, so two months, three days, four years, something like that on your Drupal site.

The Interval Field Module is just the solution for you. So it’s not something that you can use too often but there are a few situations where it can be helpful. So we’re going to go ahead and make sure we have it installed on our test site here. As you can see I have the 7.x-1.0 version installed. And so we’re just going to go to a content type. I have content type called Training. I’m just going to add a duration field to this. I’ll call it Duration and it’s actually going to be an Interval Field. So select Interval, as soon as you turn on the module you’ll have a new field type.

There’s only one widget so we’ll leave that at its default. So we click Save and now it allows you to set a few options here. So the first one is the allowed periods, so what you select here will be selectable by the user when they’re entering the value for this field. So let’s say we want minutes, hours and days. Let’s put months too, so there we go. We’ll leave out the other ones and we’ll set the default value to two hours and click Save. We’ll move this up there and now we’re going to go ahead and create a training content. We’ll create some training.

Alright so we’re going to go ahead and call this one Week Long Conference and let’s say it’s 4 days. You notice there’s only the four options that we selected here. I could add some text if I wanted to in the body and I’m just going to leave that. So you can see I now have a duration field that says 4 days. Pretty simple, this is something sometimes you can use in replacement of a date field or an addition to a date field. If you have something that spans a long duration sometimes it’s hard for people to understand how long that really is.

So a Duration Field or an Interval Field can help with that. Let’s go ahead and add another one here; let’s say we are scheduling a month long class so we want to say 1 month. Notice that it says one month here but when you save it, it notice that this is the singular so it’ll take the S of it. So if we click Save, you’ll notice it says 1 month and not 1 months. So it’s a super simple, module, there’s not much to it but it’s something that I think can be useful in specific situations where you want to really keep track of that interval versus just having a set of dates.

So go ahead and check it out, let us know what you think and if you have any other suggestions for our future videos in the Daily Dose of Drupal, make sure to head over to codekarate.com, click on Contact or send me a message on Twitter or something like that. Just get a hold of me. Until next time, see you later.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web