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.