diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 3e74216e11b9..4ce44b9d287a 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -1234,8 +1234,8 @@ private static function formatDisplayValue($value, $field, $entityId = NULL) { break; default: - // if time is not selected remove time from value - $value = substr($value, 0, 10); + //If time is not selected remove time from value. + $value = $value ? date('Y-m-d', strtotime($value)) : ''; } $customFormat = implode(" ", $customTimeFormat); } diff --git a/tests/phpunit/CRM/Core/BAO/CustomQueryTest.php b/tests/phpunit/CRM/Core/BAO/CustomQueryTest.php index 26629efcaf26..2336be65b670 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomQueryTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomQueryTest.php @@ -81,6 +81,10 @@ public function testSearchCustomDataDateFromTo() { $queryObj->_where[0][0] ); $this->assertEquals($queryObj->_qill[0][0], "date field BETWEEN 'June 6th, 2014 12:00 AM AND June 6th, 2015 11:59 PM'"); + + //CRM-17236 - Test custom date is correctly displayed without time. + $formattedValue = CRM_Core_BAO_CustomField::displayValue(date('Ymdhms'), $dateCustomField['id']); + $this->assertEquals(date('m/d/Y'), $formattedValue); } /**