how to format a date with code igniter

Posted by Jeff Davidson on Stack Overflow See other posts from Stack Overflow or by Jeff Davidson
Published on 2011-11-14T17:08:13Z Indexed on 2011/11/14 17:51 UTC
Read the original article Hit count: 186

Filed under:
|

I'm trying to figure out what I'm doing wrong here. I'm wanting to format the date_published field in my query and I'm getting an t_string syntax error in my IDE.

$this->db->select('site_news_articles.article_title, site_news_articles.is_sticky,' date_format('site_news_articles.date_published, 'f jS, Y')');

UPDATE:

function getNewsTitles($category_id) {
    $this->db->select('site_news_articles.article_title, site_news_articles.is_sticky');
    $this->db->select("DATE_FORMAT(site_news_articles.date_published, '%M %e, %Y') as formatted_date", TRUE);
    $this->db->from('site_news_articles');
    $this->db->where('site_news_articles.news_category_id', $category_id); 
    $this->db->where('site_news_articles.is_approved', 'Yes');
    $this->db->where('site_news_articles.status_id', 1);
    $this->db->order_by('site_news_articles.date_published', 'desc');  
    $this->db->limit(10);
    $query = $this->db->get();
    return $query->result_array(); 
}

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM (site_news_articles) WHERE site_news_articles.news_category_id = 2 A' at line 2

SELECT site_news_articles.article_title, site_news_articles.is_sticky, DATE_FORMAT(site_news_articles.date_published, '%M %e, %Y') as formatted_date FROM (site_news_articles) WHERE site_news_articles.news_category_id = 2 AND site_news_articles.is_approved = 'Yes' AND site_news_articles.status_id = 1 ORDER BY site_news_articles.date_published desc LIMIT 10

Filename: /home/xtremer/public_html/models/sitemodel.php

Line Number: 140

© Stack Overflow or respective owner

Related posts about php

Related posts about codeigniter