php remove time from custom datetime formatting
<p>How could I set the <code>isClean</code> to automatically remove the time if its set to: 00:00:00. So if a time hasn't been set or midnight then dont display anything.</p>

<pre><code>/**
 * Perform datetime formatting operations.
 * - relative: if today/yesterday
 * - clean: remove time if 00:00
 *
 * @param string $var
 * @param string||array $params
 * @return string
 */
protected function datetime($var,$params) {
    date_default_timezone_set("Europe/London");
    // 1970-01-01 00:00:00
    $template = $params;
    $isRelative = false;
    $isClean = false;
    if (is_array($params) &amp;&amp; !empty($params['template'])) {
        if (!empty($params['relative']) &amp;&amp; trim(strtolower($params['relative'])) == 'yes') {
            $isRelative = true;
        }
        if (!empty($params['clean']) &amp;&amp; trim(strtolower($params['clean'])) == 'yes') {
            $isClean = true;
        }
        $template = $params['template'];
    }

    // check if its empty or not?
    if(strlen($var)&lt;1) return $var;

    // ignore invalue request throw error?
    if(is_array($template)) return $var;

    if($var == "NOW") $var = date("d-m-Y H:i:s");

    $out = $var;
    if(strpos($out,":") === false) {
        $out = trim($out);
        $out .= " 00:00:00";
    }

    if(($timestamp = $this-&gt;getTimestamp($out)) !== false) {
        if ($isRelative) {
            $time = date('H:i', $timestamp);
            if (date('Ymd') == date('Ymd', $timestamp)) {
                // Today
                return sprintf("Today at %s", $time);
            } else {
                // Yesterday?
                $today = strtotime("12:00:00");
                $yesterday = strtotime('-1 day', $today);

                if (abs($yesterday - $timestamp) &lt; 12*3600) {
                    return sprintf("Yesterday at %s", $time);
                }
            }
        }

        $var = date($template,$timestamp);
    }

    return $var;
}
</code></pre>

<p>More info: our CMS works by reading the <code>&lt;match&gt;</code> and automatically matching this to the database column name OR we manually write <code>&lt;format&gt;long_datetime&lt;/format&gt;</code>.</p>

<p>So the main reason for this method is to :</p>

<blockquote>
  <ol>
  <li>Connect the XML options with php datetime.</li>
  <li>Add extra functionality such as NOW, relative dates and now the ability to clean up the datetime if set to 0s</li>
  </ol>
</blockquote>
