I have a Date field on a content type. I’m trying to render it so that just the Month and Day are visible, but I need each in a separate .
I think the most appropriate place to do this is in the preprocess function for the node theme function. Within that function, here’s the date field on the node object:
What is the appropriate way to convert this to something I can run a custom date formatter on, so I can get the month and the day separately?
This is my current approach:
$date_field = $node->field_event_date_time[$node->language][0]; $date_object = new DateObject($date_field['value'], new DateTimeZone($date_field['timezone_db'])); $variables['event_month'] = date_format_date($date_object, 'custom', 'M'); $variables['event_day'] = date_format_date($date_object, 'custom', 'j');
But it does seem a bit messy, and I’ve noticed is that the field won’t always have the language array key, so that complicates it a bit further.