SQL日期选取
程序员文章站
2022-04-08 20:51:47
...
我的数据库里有个表是日期的
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']
麻烦大家帮个忙。我是个新手。正在学习中
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……
感谢.现在明白了大概要怎么弄了.调试了一下也出来相应的效果.满分
推荐阅读
-
那些年我们在python掉进的坑系列之一pandas的to_sql
-
CentOS随笔 - 5.CentOS7安装Sql Server 2017
-
SQL Server中关于跟踪(Trace)那点事
-
FineReport报表怎么对日期进行自动计算
-
sql server 性能调优 资源等待之PAGEIOLATCH
-
获取两个日期间隔时间的shell脚本代码
-
Excel2010从函数库类别菜单中选择TODAY函数输入当天日期
-
每天都用的三个Excel对齐技巧即跨列居中与缩进对齐及日期对齐
-
java查看变量类型的方法(将日期从string转成date)
-
用TEXT函数解决日期用&连接字符日期变成数字格式的问题