$field_name     = $vars["field_info"]["field_name"];
$date           = $vars["data"][$field_name];
$display_format = $vars["settings"]["display_format"];
$atzo           = $vars["settings"]["apply_timezone_offset"];
$account_info   = isset($vars["account_info"]) ? $vars["account_info"] : array();

if (empty($date)) {
  $value = "";
} else { 
  if (strpos($display_format, "datetime:") === 0) {
    $parts = explode(" ", $date);
    switch ($display_format) {
      case "datetime:dd/mm/yy|h:mm TT|ampm`true":
        $date = substr($date, 3, 2) . "/" . substr($date, 0, 2) . "/" . substr($date, 6);
        break;
      case "datetime:dd. mm. yy|hh:mm":
        $date = substr($date, 4, 2) . "/" . substr($date, 0, 2) . "/" . substr($date, 8, 4) . " " . substr($date, 14);
        break;
    }
  } else {
    if ($display_format == "dd/mm/yy") {
      $date = substr($date, 3, 2) . "/" . substr($date, 0, 2) . "/" . substr($date, 6);
    } else if ($display_format == "dd. mm. yy") {
      $parts = explode(" ", $date);
      $date = trim($parts[1], ".") . "/" . trim($parts[0], ".") . "/" . trim($parts[2], ".");
    }
  }
  $time = strtotime($date);
  
  // lastly, if this field has a timezone offset being applied to it, do the
  // appropriate math on the date
  if ($atzo == "yes" && !isset($account_info["timezone_offset"])) {
    $seconds_offset = $account_info["timezone_offset"] * 60 * 60;
    $time += $seconds_offset;
  }
  $value = date("Y-m-d H:i:s", $time);
}