每天根据日期查询 [英] Querying on daily basis based on date
问题描述
我有一张与付款有关的表.
我需要每天进行搜索
而是采用"2012-04-01 13:00:30.687"日期格式
列名称为PaymentDate
我可以按年份进行搜索.
但我需要按日期
请帮助我
我正在使用
I have a table related to payments.
I need to search on daily basis
but it is in "2012-04-01 13:00:30.687" date format
column name is PaymentDate
i am able to search by year.
but i need by date
Please help me
i am using
select * from online_payments where PaymentDate like '%2012%'
这给出了全年的结果,但是我只需要特定的日期.
我尝试过但找不到.
现在紧急了.
this is giving whole year results but i need only particular date.
I tried but not able to find.
Its some what urgent now.
Can any one help me please.
推荐答案
尝试:
SELECT * FROM Student WHERE dat2 >= '2012-02-12' and dat2 < '2012-02-13'
看一下CONVERT
命令. http://msdn.microsoft.com/en-us/library/aa226054 (v = sql.80).aspx [
Have a look at theCONVERT
command. http://msdn.microsoft.com/en-us/library/aa226054(v=sql.80).aspx[^]
With this command you do your query like this:
select * from online_payments where CONVERT(varchar(8), PaymentDate,112) = '20120401'
问候
Michel
regards
Michel
尝试如下.
Try like below.
select *
from online_payments
where DateAdd(day, DateDiff(day, 0, PaymentDate), 0) = '2012-04-01'
DateAdd(day,DateDiff(day,0,PaymentDate),0)删除时间并单独获取日期
DateAdd(day, DateDiff(day, 0, PaymentDate), 0) removes time and get the date alone
这篇关于每天根据日期查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!