Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8659943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:07:53+00:00 2026-06-12T16:07:53+00:00

How could I set the isClean to automatically remove the time if its set

  • 0

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 :

  1. Connect the XML options with php datetime.
  2. Add extra functionality such as NOW, relative dates and now the ability to clean up the datetime if set to 0s
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:07:55+00:00Added an answer on June 12, 2026 at 4:07 pm

    Your request is not clear but with clarification on $var and to automatically remove the time am sure this would help

    $xml = '
    <patterns>
            <pattern>
        <match>date</match>
        <datetime>d/m/Y</datetime>
    </pattern>
    
    <pattern>
        <match>datetime</match>
        <datetime>d/m/Y H:i</datetime>
    </pattern>
    
    <pattern>
        <match>datetime_nice</match>
        <datetime>jS F Y, H:i</datetime>
    </pattern>
    
    <pattern>
        <match>datetime_iso</match>
        <datetime>c</datetime>
    </pattern>
    
    <pattern>
        <match>datetime_relative</match>
        <datetime>
            <relative>YES</relative>
            <clean>yes</clean>
            <template>jS M y, H:i</template>
        </datetime>
    </pattern>
    
    <pattern>
        <match>date_relative</match>
        <datetime>
            <relative>yes</relative>
            <template>jS M, Y</template>
        </datetime>
    </pattern>
    
    <pattern>
        <match>long_datetime</match>
        <datetime>
            <relative>YES</relative>
            <template>jS M Y \a\t H:i</template>
        </datetime>
    </pattern>
    </patterns>     
    ';
    
    echo simpleDateTime("long_datetime",$xml);
    

    Output

    Yesterday at 11th Oct 12 
                              ^--- Date was cleaned instead of H:i in the template
    

    Function Used

    function simpleDateTime($var, $xml) {
        $list = getList($xml);
        $list = $list[$var];
        $date = new DateTime("now", new DateTimeZone("Europe/London"));
        $output = $date->format($list['template']);
        if ($list['clean'] === true) {
            $date->setTime(0, 0, 0);
            $output = str_replace("00:00", "", $date->format($list['template']));
        }
        $output = trim($output);
        $output = rtrim($output, ",");
        if ($list['reletive'] === false) {
            return sprintf("Today at %s", $output);
        } else {
            $date->modify("+1 day");
            return sprintf("Yesterday at %s", $output);
        }
    }
    
    function getList($xml) {
        $xml = new SimpleXMLElement($xml);
        $list = array();
        foreach ( $xml->children() as $pattern ) {
            $item = array();
            $item['reletive'] = false;
            $item['clean'] = false;
    
            if (isset($pattern->datetime->template)) {
                $item['reletive'] = (strtoupper($pattern->datetime->relative) == "YES") ? true : false;
                $item['clean'] = (strtoupper($pattern->datetime->clean) == "YES") ? true : false;
                $item['template'] = (string) $pattern->datetime->template;
            } else {
                $item['template'] = (string) $pattern->datetime;
            }
    
            $list[(string) $pattern->match] = $item;
        }
        return $list;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering how I could set the background image to keep its position
In ExtJS 3, you could set enableHdMenu to false on a Grid to remove
In former versions of Parallel Extensions you could set the number of threads: enumerable.AsParallel(numberOfThreads)
I was wondering how I could set up css pseudo classes, specifically hover so
I just begin programming with android home widget, so i could set text to
How could I set the value of the Height property of a WPF control
Where Could I set the application name that user see in home screen, under
I need to compile the unit with /EHsc option, how could i set this
I could use another set of eyes - perhaps I am missing somehting obvious.
How could one test whether a set of modules is installed, given the names

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.