CodeIgniter Forums

Full Version: How to select date(with custom format) in mysql table
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]LoganPHP[/eluser]
hi i’m trying to use mysql date_format with CI Active records method $this->db->setect() to select but getting mysql syntax error.....

so any help me..How to select date with custom format from mysql table date(date type) column?

Thanks in advance
Logan

El Forum

[eluser]CI_avatar[/eluser]
if you have problems with CI date_format please use the php date().

El Forum

[eluser]LoganPHP[/eluser]
i got solution.........

Code:
$query = $this->db->query("Select job_title,date_format(job_date,'%d-%m-%Y') as job_date,job_description,contact FROM jobs_management  LIMIT $offset, $limit");

Example with pagination:
Code:
function select_pagination($limit, $offset)
    {
        if($offset>1)
        {
            $offset=$offset;
        }
        else
        {
            $offset=0;
        }
        $query = $this->db->query("Select job_title,date_format(job_date,'%d-%m-%Y') as job_date,job_description,contact FROM jobs_management  LIMIT $offset, $limit");
        return $query->result();
    }