Add support for most common date field formats. Currently only timestamp is supported (node created, updated).

Comments

pol’s picture

I tried with this bit of code, and it works pretty good, so you can use any time format.

      // Apply additional field-level processing
      if(isset($fields['startDate'])) {
        if (is_array($fields['startDate'])) {
          $date_tmp = array_shift($fields['startDate']);
          $fields['startDate'] = strtotime($date_tmp['value']);
        }
        $fields['startDate'] = format_date($fields['startDate'], 'custom', 'Y,m,d');
      }
chromix’s picture

I used this code, instead, as strtotime can throw errors sometimes. The only hitch is that the Date field must be datestamp. This also supports endDates, handily enough.

      if(isset($fields['startDate'])) {
        if (is_array($fields['startDate'])) {
          // Processing for datestamp fields from the Date module
          $date_tmp = array_shift($fields['startDate']);
          $fields['startDate'] = $date_tmp['value'];
          if (isset($date_tmp['value2'])) {
            $fields['endDate'] = $date_tmp['value2'];
          }
          else {
            $fields['endDate'] = $fields['startDate'];
          }
        }
        $fields['startDate'] = format_date($fields['startDate'], 'custom', 'Y,m,d');
      }
pol’s picture

The first parameter of format_date() must be a timestamp and $fields['startDate'] is not always a timestamp, that's why I use strtotime().

I made some improvements to the module, I'll post them tonight.

pol’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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