zend-db icon indicating copy to clipboard operation
zend-db copied to clipboard

Issues in date format using new Expression("date_format(client_created, '%m-%d-%Y')")

Open kudeepak opened this issue 9 years ago • 1 comments

https://github.com/zendframework/zendframework/blob/release-2.4/library/Zend/Db/Sql/Expression.php

As we checked, it has issues to format the date. When we have taken replaced the code of 2.4 with version 2.3, it is running proper You can look into the following function of the file "https://github.com/zendframework/zendframework/blob/release-2.4/library/Zend/Db/Sql/Expression.php"

 /**
     * @return array
     * @throws Exception\RuntimeException
     */
    public function getExpressionData()
    {
        $parameters = (is_scalar($this->parameters)) ? array($this->parameters) : $this->parameters;
        $types = array();
        $parametersCount = count($parameters);
        if ($parametersCount == 0 && strpos($this->expression, self::PLACEHOLDER) !== false) {
            // if there are no parameters, but there is a placeholder
            $parametersCount = substr_count($this->expression, self::PLACEHOLDER);
            $parameters = array_fill(0, $parametersCount, null);
        }
        for ($i = 0; $i < $parametersCount; $i++) {
            $types[$i] = (isset($this->types[$i]) && ($this->types[$i] == self::TYPE_IDENTIFIER || $this->types[$i] == self::TYPE_LITERAL))
                ? $this->types[$i] : self::TYPE_VALUE;
        }
        // assign locally, escaping % signs
        $expression = str_replace('%', '%%', $this->expression);
        if ($parametersCount > 0) {
            $count = 0;
            $expression = str_replace(self::PLACEHOLDER, '%s', $expression, $count);
            if ($count !== $parametersCount) {
                throw new Exception\RuntimeException('The number of replacements in the expression does not match the number of parameters');
            }
        }
        return array(array(
            $expression,
            $parameters,
            $types
        ));
    }

kudeepak avatar Jul 21 '16 12:07 kudeepak

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at https://github.com/laminas/laminas-db/issues/103.

michalbundyra avatar Jan 16 '20 19:01 michalbundyra