SQL date selection

Source: Internet
Author: User
Select SQL date. a table in my database is of the date type.
News_last_modified
2013-04-12 13:04:18

This is the style.

How do I select a date instead of a time?
The front-end code 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. required age_id = \''. (int) $ _ SESSION ['ages _ 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 help me. I am a newbie. Learning...


Reply to discussion (solution)

Date ()

$str="2013-04-12 13:04:18";$ar=explode(" ",$str);print_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. required age_id = \''. (int) $ _ SESSION ['ages _ id']. '\') and n. news_status = \ '1 \''. 'order by n. article_id DESC limit 6 ';

Or you can convert it to 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 ......


Thanks. now I understand how to get it. After debugging, it also shows the corresponding effect. full score.

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.