HOWTO: Change ListView DateTime field to only show date

sugarcrmdevelopers —  January 17, 2012 — Leave a comment

Here’s a interesting question that recently came up on the forums:

How and where can I make a change so that for a Listview screen, only the date appears for the Date Created column, not date and time?

You can do this fairly easily by customizing the Datetime SugarField, by adding the following code into the custom/include/SugarFields/Fields/Datetime/SugarFieldDatetime.php file:

require_once('include/SugarFields/Fields/Datetime/SugarFieldDatetime.php');

class CustomSugarFieldDatetime extends SugarFieldDatetime
{
    function getListViewSmarty($parentFieldArray, $vardef, $displayParams, $col) 
    {
        $tabindex = 1;
        $isArray = is_array($parentFieldArray);
        $fieldName = $vardef['name'];

        if ($fieldName == 'DATE_ENTERED') {
            if ( $isArray ) {
                $parentFieldArray[$fieldName] = $GLOBALS['timedate']->getDatePart($parentFieldArray[$fieldName]);
            }
            else {
                $parentFieldArray->$fieldName = $GLOBALS['timedate']->getDatePart($parentFieldArray->$fieldName);
            }
        }

        if ( $isArray ) {
            $fieldNameUpper = strtoupper($fieldName);
            if ( isset($parentFieldArray[$fieldNameUpper])) {
                $parentFieldArray[$fieldName] = $this->formatField($parentFieldArray[$fieldNameUpper],$vardef);
            } else {
                $parentFieldArray[$fieldName] = '';
            }
        } else {
            if ( isset($parentFieldArray->$fieldName) ) {
                $parentFieldArray->$fieldName = $this->formatField($parentFieldArray->$fieldName,$vardef);
            } else {
                $parentFieldArray->$fieldName = '';
            }
        }
        $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex, false);

        $this->ss->left_delimiter = '{';
        $this->ss->right_delimiter = '}';
        $this->ss->assign('col',$vardef['name']);

        return $this->fetch($this->findTemplate('ListView'));
    }
}

You may need to do a quick rebuild and repair for this change to take affect, but once it does you should no longer see the time part in the Date Created field on ListViews.

No Comments

Be the first to start the conversation!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s