
*
from
用户
where
工资=textBox.Text
and
convert(char(10),日期,120)
=
formatdatetime('YYYY-MM-DD',dp1.datetime)
日期可以以字符串的形式放到sql语句中
'YYYY-MM-DD'或'YYYY-MM-DD
hh:mm:ss'
2.用between
...
and
或用
...and
Year(日期)
=
Year(cast('2008-05-14'
as
datetime))
and
month(日期)
=
month(cast('2008-05-14'
as
datetime))
查询2011的数据:select*
from
表
where
year(date)='2011'
查找月份为12的数据:select
*
from
表
where
month(date)='12'
查找天数为本年第二天的数据:select
*
from
表
where
dayofyear(date)='2'
我解释一下:
select
*
from
表
where
这是必须的
year,month,dayofyear是mysql的函数,分别是取得年,月,和当前时间在本年是第几天的3个函数
date就是你保存时间的字段
等号后面的当然条件啦。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)