数据库里日期比较

数据库里日期比较,第1张

1.select

*

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就是你保存时间的字段

等号后面的当然条件啦。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/6698885.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-03-26
下一篇2023-03-26

发表评论

登录后才能评论

评论列表(0条)

    保存