Html::convDate PHP Method

convDate() static public method

Convert a date YY-MM-DD to DD-MM-YY for calendar
static public convDate ( $time, $format = null )
$time date date to convert
$format (default null)
    static function convDate($time, $format = null)
    {
        if (is_null($time) || $time == 'NULL') {
            return NULL;
        }
        if (!isset($_SESSION["glpidate_format"])) {
            $_SESSION["glpidate_format"] = 0;
        }
        if (!$format) {
            $format = $_SESSION["glpidate_format"];
        }
        switch ($format) {
            case 1:
                // DD-MM-YYYY
                $date = substr($time, 8, 2) . "-";
                // day
                $date .= substr($time, 5, 2) . "-";
                // month
                $date .= substr($time, 0, 4);
                // year
                return $date;
            case 2:
                // MM-DD-YYYY
                $date = substr($time, 5, 2) . "-";
                // month
                $date .= substr($time, 8, 2) . "-";
                // day
                $date .= substr($time, 0, 4);
                // year
                return $date;
            default:
                // YYYY-MM-DD
                if (strlen($time) > 10) {
                    return substr($time, 0, 10);
                }
                return $time;
        }
    }

Usage Example

 function displayValue($output_type, $row)
 {
     if (isset($row[$this->name]) && $row[$this->name]) {
         return Html::convDate($row[$this->name]);
     }
     return '';
 }
All Usage Examples Of Html::convDate
Html