You are here

function mailchimp_format_date in Mailchimp 7.4

Same name and namespace in other branches
  1. 7.5 mailchimp.module \mailchimp_format_date()

Formats a date string before sending to Mailchimp's API.

Parameters

string $input: The input date.

Return value

string The formatted date.

See also

http://kb.mailchimp.com/lists/growth/format-guidelines-for-your-import-f...

1 call to mailchimp_format_date()
mailchimp_mergevars_populate in ./mailchimp.module
Replace an array of merge field placeholder tokens with their values.

File

./mailchimp.module, line 1878
Mailchimp module.

Code

function mailchimp_format_date($input) {

  // Attempt to convert date string to a timestamp.
  // Remove time in standard Drupal date formats. It confuses strtotime().
  $date = trim(preg_replace('/(- )?[0-9]+:[0-9]+/', '', $input));
  $timestamp = strtotime($date);
  if ($timestamp !== FALSE) {

    // Return formatted date.
    return date('Y-m-d', $timestamp);
  }
  else {

    // Unable to parse the date string.
    return NULL;
  }
}