SQL Date Selection

Source: Internet
Author: User
There's a table in my database that's dated.
News_last_modified
2013-04-12 13:04:18

It's the style.

How do I select a date instead of a time?
The code for the front desk is like this

Require_once (dir_ws_classes. ' news.php ');

$news _list_by_author_sql= ' Select N.article_id,n.news_last_modified, Nt.news_article_name from '. Table_news_articles. ' N left join '. Table_news_articles_text. ' NT on (n.article_id = nt.article_id and nt.language_id = \ '. (int) $_session[' languages_id '. ' \ ') and n.news_status = \ ' 1\ '. ' ORDER by n.article_id DESC limit 6 ';
$news = $db->execute ($news _list_by_author_sql);

if ($news->recordcount () > 0) {
$i = 0;
$article _array = Array ();
while (! $news->eof) {
$article _array[$i] = Array (
' ArticleID ' = $news->fields[' article_id '],
' Articledate ' = $news->fields[' news_last_modified '],
' ArticleName ' = stripslashes ($news->fields[' news_article_name '),
);
$i + +;
$news->movenext ();
}//end while
} else {
$articlesNotFound = true;
}

?>
-------------------------------------
' articledate ' = $news->fields[' news_last_modified ']

Please do me a favor. I'm a novice. Learning in progress


Reply to discussion (solution)

Date ()

$str = "2013-04-12 13:04:18"; $ar =explode ("", $str);p Rint_r ($ar);//array ([0] = 2013-04-12 [1] = = 13:04:18) $t = Explode ("", $news->fields[' news_last_modified ']); ' Articledate ' = $t [0],

$news _list_by_author_sql= ' Select n.article_id, Date_format (n.news_last_modified, "%y-%m-%d") as News_last_modified, Nt.news_article_name from '. Table_news_articles. ' N left join '. Table_news_articles_text. ' NT on (n.article_id = nt.article_id and nt.language_id = \ '. (int) $_session[' languages_id '. ' \ ') and n.news_status = \ ' 1\ '. ' ORDER by n.article_id DESC limit 6 ';

Or you can turn it in PHP.

' Articledate ' = Date ("y-m-d", Strtotime ($news->fields[' news_last_modified ')),

$news _list_by_author_sql= ' Select N.article_id,date_format (n.news_last_modified, "%y-%m-%d") as News_last_modified, Nt.news_article_name from '. Table_news_articles. ' N left join '. T......


Thank you. Now I understand how to do it. Debugging a bit also come out corresponding effect.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.