I've got a custom field that formats particular dates in our athletic schedule, and then outputs the others normally. The problem is that they don't output like they do in normal date fields.
Example:
12/02/2009 - 6:30pm VS. 2009-12-03 01:30:00
Here's my current code:

if (preg_match ('/06:00:00/', $data->node_data_field_date_field_date_value) || preg_match ('/07:00:00/', $data->node_data_field_date_field_date_value))
echo substr($data->node_data_field_date_field_date_value, 0, -8) . ' - TBA';
else 
echo $data->node_data_field_date_field_date_value;

(the 'or' in there is to accomodate daylight savings changes)

I saw another post that would likely get the job done, but it calls the php date function directly, and I'd like to keep the date formatting consistent with my drupal date settings, so that if we were to ever change the global date formatting options in drupal, these schedules would stay consistent with dates across our entire site. I was able to come close by using the following code:

if (preg_match ('/06:00:00/', $data->node_data_field_date_field_date_value) || preg_match ('/07:00:00/', $data->node_data_field_date_field_date_value))
echo substr($data->node_data_field_date_field_date_value, 0, -8) . ' - TBA';
else 
echo format_date($data->node_data_field_date_field_date_value, 'small');

However, with this, the dates are apparently getting mangled, because I get '12/31/1969 - 6:33pm' as the output for every date that is processed by the 'else' section.
Am I on the right track at all? What am I missing here?

Thanks for such a great plugin, I was able to use it to solve another formatting issue, and it was awesome.

Comments

dawsonit’s picture

To follow up on this, I tried the solution the other post used, and it doesn't work either. It outputs the same date as above (December 31, 1969...).
So now I'm totally stuck.

dawsonit’s picture

so it starts to make more sense now. CCK stores the value as a human readable date. the format_date and date functions expect a unix timestamp. So... why the heck is cck storing dates like that, and how do I convert them to unix timestamps?

dawsonit’s picture

Status: Active » Fixed

So, to solve my own problem here... I had set up the CCK field as a DateTime field, which made it into a human readable form in the database. Instead, I should have used the Datestamp field type which gives the desired results.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.