How could I set the isClean 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.
/**
* 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) && !empty($params['template'])) {
if (!empty($params['relative']) && trim(strtolower($params['relative'])) == 'yes') {
$isRelative = true;
}
if (!empty($params['clean']) && trim(strtolower($params['clean'])) == 'yes') {
$isClean = true;
}
$template = $params['template'];
}
// check if its empty or not?
if(strlen($var)<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->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) < 12*3600) {
return sprintf("Yesterday at %s", $time);
}
}
}
$var = date($template,$timestamp);
}
return $var;
}
More info: our CMS works by reading the <match> and automatically matching this to the database column name OR we manually write <format>long_datetime</format>.
So the main reason for this method is to :
- Connect the XML options with php datetime.
- Add extra functionality such as NOW, relative dates and now the ability to clean up the datetime if set to 0s
Your request is not clear but with clarification on
$varandto automatically remove the timeam sure this would helpOutput
Function Used