Split a date field output into two spans 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-&gt;field_event_date_time[$node-&gt;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.
If your current approach works, consider sticking with it.  Use field_get_items() to get past the "field won't always have the language" problem.

To answer the original question, at admin/config/regional/date-time you'll find a tab to create a new format.  You can somewhat laboriously create a format based on something like:

&lt;\s\p\a\n \c\l\a\s\s="\f\o\o"&gt;l F j&lt;/\s\p\a\n&gt; - &lt;\s\p\a\n \c\l\a\s\s="\b\a\r"&gt;g:i a&lt;/\s\p\a\n&gt;


All the backslashes may not be necessary, but you have to backslash escape any character that is a special date code.

Then edit a type or make a new one that uses your format with the markup built in.