2

I have a content type that uses Date, it has a start date with time, and end date and can even repeat. But I need to hide the part of date that handles the end date and leave just the time, most events in this content type happen the same day, so that the user doesn't gets confused when making a new node of this particular content type. Any ideas?

3 Answers 3

5

To control the display of the date field, you need to do a few things:

  1. Add a date format that will match your requirements, for example, display time only from the date. To do that, go to Configuration > Regional and language > Date and time > tab Formats (/admin/config/regional/date-time/formats). Add a new format, for example, for time only, add g:i a

  2. Add a date type (admin/config/regional/date-time) - for example, call it "Time only" and use that new format from #1 that was added (on the list of formats you should now see the time only value)

  3. In your content type, under Display tab, change the date field to use that new date display "Time only". Optionally, if you want to change how the date is displayed in a View generated page, select that new date display in the date field display options.

1
  • The thing is I need to use the full date with time in the start date, but just the time in the end date, and I can't use a date format when creating the Date field in the content type. I'll edit my question acordingly
    – HaPK
    Mar 5, 2015 at 16:18
3

Yeah, Drupal date fields just don't think this way. Maybe a better solution would be to only store the starting date and time in your date field, and then have a second field for the length of the event. Then a third field would compute the end time.

Or another approach might be to use Javascript to pre-populate the end time with the date from the start time.

2
  • How would that Javascript be? That could be part of the solution
    – HaPK
    Mar 5, 2015 at 19:14
  • 1
    I don't know JS well enough to provide you with the code. But you can have the script trigger on leaving focus of the date field so that each time someone clicks on it and then leaves it, the date value is grabbed and put in the second date field. For example in jQuery you could use .blur(), or .change() would be even better. api.jquery.com/category/forms
    – R. Durham
    Mar 6, 2015 at 16:29
1

Depending on how you're using the date field on other areas of your site, you could try splitting the date and time information into different fields. For example, you could have a single date field, a start time field, and an end time field. That would allow you to have more granular control over the display of each individual field. Granted, it would lock users into entering events that only spanned a single day (but the idea you proposed above will do that anyway).

If you need to keep your exact field configuration, you'll probably have to write a custom module to control the display of your end date field.

3
  • Could you guide on how to make that custom module?
    – HaPK
    Mar 5, 2015 at 19:14
  • @HaPK Depends on how your field is set up, and how it's displayed on the node add form. But if your end date has 2 separate inputs (one for the date and one for the time), you might be able hide the date one with CSS (although that's not really the "Drupal" way). Otherwise it's very tough to say without knowing your specific setup. Mar 5, 2015 at 20:35
  • Splitting the date and time information, it would be harder to implement repeating events, as the OP states that the events "can even repeat." Apr 10, 2017 at 12:04

Your Answer

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

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