Not sure if this is possible - if not - then switch it to a feature request :) And this might be directed at views rather than date - not sure.

Given a date field on a node type - where it is set to also provide an optional To date - is it possible in block and/or page view to have different formatting?

An example use case is when providing a block view of customer meetings this week.

We would really like:

dd/mm/yy hh:mm - hh:mm

rather than

dd/mm/yy hh:mm - dd/mm/yy hh:mm

Is this possible?

CommentFileSizeAuthor
#8 Picture 21_0.png6.29 KBkarl sf

Comments

chrissearle’s picture

1) The type of field: Date
2) The type of widget: Have used both selector or text on different nodes
3) The timezone option being used: site timezone everywhere GMT+1. Note - system clock runs GMT
4) Whether you are using the 'multiple' option: No
5) Whether you are using the 'required' option: Yes in this case

karens’s picture

Yes you can do this in your theme. Look at the bottom of the date.module and you will see a theme called theme_date_display_combination($field, $date1, $date2). Copy that theme to your phptemplate file and rename it to mythmename_date_display_combination() and you can change the way the date is displayed.

The $field array has info about the field name ($field['field_name']), content type ($field['type_name']) and the field and widget settings. $date1 is the 'from' date and $date2 is the 'to' date.

This is a new feature so I don't have documentation for it yet. You may find when you use it that you need more info to get the right display. If so, report back here and we can tweak it.

The other thing you can do is use css to hide parts of the date. There is a class for the separator and each date part, and you could add some css to use display:hidden on the separator and the second date if it is displayed in the left or right column, for instance.

chrissearle’s picture

OK - many thanks. We're using garland so I'll take a quick copy of that and have a go.

aether’s picture

I too am trying to accomplish this display of event times for a current project. I have followed the instructions above and am able to get the format to look the way I want but the time for $date2 gets returned incorrectly.

The modified code in I have placed in phptemplate is as follows:

function mythemename_date_display_combination($field, $date1, $date2 = NULL) {
  
  $formattedDate2 = date("g:ia", strtotime($date2));
  
  if ($date1 == $date2 || empty($date2)) {
    return '<span class="date-display-single">'. $date1 .'</span>';
  }
  else {
    return '<span class="date-display-start">'. $date1 .'</span><span class="date-display-separator"> - </span><span class="date-display-end">'. $formattedDate2 .'</span>';
  }
}

If I the event that I enter into Drupal is this:

Feb 6 2007 - 12:00pm -- Feb 6 2007 - 12:00pm - 2:00pm

the date gets dispalyed on the web page as:

Feb 6 2007 - 12:00pm - 5:00pm

but the correct times should be this:

Feb 6 2007 - 12:00pm - 2:00pm

$date2 always gets returned as 5:00pm even when I change the time in Drupal.

I am using datestamp as the field type in Drupal 5.1 with php 5.1.6

I am a php novice so I may be way off base. Any ideas?

aether’s picture

Version: 5.x-1.1 » 5.x-1.2

Sorry, failed to include this info:

1) Field type: Datestamp
2) Widget: tried all 3
3) Timezone: GMT -7:00
4) Whether you are using the 'multiple' option: No
5) Whether you are using the 'required' option: No

karens’s picture

Status: Active » Fixed

There were several fixes committed today and one or more of them should have fixed the problem with the 'to' date.

aether’s picture

Perfect! The code in my post above now displays the time properly. Thanks.

karl sf’s picture

StatusFileSize
new6.29 KB

I haevn't done anything to the phpTemplate.engine before, but I pasted the above code at the end of the file. Dates displayed the same, showing the date twice, rather than a start and end date for the same day. Was I supposed to edit the code or put it in as is. I used all ot Jtomlinson's code. Did that include specifics to your site, or can it work in my phptemplate?

Or was there some menu in drupal admin taht i can reset how the date is treated? Thanks. See image for how date shows now. I would like it to show as Wed Feb. 14, 2:00- 5:00 pm. for example.

chrissearle’s picture

Editing the phptemplate means editing the template file in the theme (for me under a modified copy of garland the file template.php worked well). You don't need to change the engine files themselves.

My only issue is that I use a non-english date format so strtotime wobbles. I just hacked it with substring instead since we have a fixed date format.

aether’s picture

karl sf,

As chrissearle stated, this code goes in the template.php file in the folder for the specific theme that you are using:

<?php
function mythemename_date_display_combination($field, $date1, $date2 = NULL) {
 
  $formattedDate2 = date("g:ia", strtotime($date2));
 
  if ($date1 == $date2 || empty($date2)) {
    return '<span class="date-display-single">'. $date1 .'</span>';
  }
  else {
    return '<span class="date-display-start">'. $date1 .'</span><span class="date-display-separator"> - </span><span class="date-display-end">'. $formattedDate2 .'</span>';
  }
}
?>

If the theme does not have a template.php file simply create one and paste the code inside it. In either case, be sure to change "mythemename" in the function to the name of the theme you have placed the code into, i.e. garland_date_display_combination.

Hope this helps.

Radiating Gnome’s picture

This works for me just fine (I needed to adjust my code a bit to get a formatted version of the first date, too) but what I'm not getting is times adjusted for the time zone.

If I try to do that manually, I have daylight savings time problems, and I'm sure there's a more graceful way to handle this. Any suggestions?

Anonymous’s picture

Status: Fixed » Closed (fixed)