SQL日期選取

來源:互聯網
上載者:User
我的資料庫裡有個表是日期的
news_last_modified
2013-04-12 13:04:18

是這個樣式的。

如何只選擇日期而不選擇時間呢?
前台的代碼是這樣的

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']

麻煩大家幫個忙。我是個新手。正在學習中


回複討論(解決方案)

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.language_id = \'' . (int)$_SESSION['languages_id'] . '\') and n.news_status = \'1\'' . ' order by n.article_id DESC limit 6 ';

或者在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……


感謝.現在明白了大概要怎麼弄了.調試了一下也出來相應的效果.滿分

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.