Home >Backend Development >PHP Tutorial >MYSQL中截取数据库时间字段等于提交上来的值怎么写MYSQL语句

MYSQL中截取数据库时间字段等于提交上来的值怎么写MYSQL语句

WBOY
WBOYOriginal
2016-06-23 13:57:171038browse

bl_time是字段(如2014-05-09 11:33:20)
$Year是表单提交上来的值(如2014)

.....where YEAR('ruku.bl_time')=" . $Year;

意思就是截取bl_time字段的年份等于表单提交上来的$Year的值
where 后面的语句怎么写才正确?


回复讨论(解决方案)

$sql = "select * from table where year(bl_time) = '$Year'";

截取年份的对了
那截取月和日分别是用什么?
month(bl_time)和day(bl_time)吗?试了,好像不行

用month() 和 day() 是没问题的,你试了吗。

搞了半天,原来是我提交表单里的值没有传过去,难怪不行咯

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn