如何比较日期时间的日期? [英] How to compare the dates in datetime?
本文介绍了如何比较日期时间的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何比较日期时间的日期?例如,我在db中有一个日期为2008-06-26 16:19:21.890的字段,并且我想从日历控件中获取小于或等于所选日期的数据?我把日期传递给mm / dd / yyyy。在选择26/06/2008日期时,我没有收到该日期的数据。早期数据的数据很好。想要更改Sql本身。
How to compare the dates in datetime? For instance I am having a field with date as 2008-06-26 16:19:21.890 in db and and I want to fetch the data less than or equal to the selected date from calendar control? I am passing the date as mm/dd/yyyy . On selecting 26/06/2008 date I am not getting data on that date. Earlier dates data are fetched fine. Want to change in Sql itself.
SELECT C.CorporateId, C.CorporateName AS CorporateName,E.EmpId, E.FirstName, E.LastName,
E.IBAN as AccountNo,E.CitizenId,[dbo].[fnMaskCardNo](E.CardNo)as CardNo, E.PassportId,
E.NationalityCode, Co.CountryName,E.CardStatus,
C.IsDeleted,E.DOB,E.RHFReceivedDate As Date,
CONVERT(INT,MONTH(E.RHFReceivedDate)) as ModifiedMonth,
CONVERT(INT,year(E.RHFReceivedDate)) as ModifiedyEAR
FROM Employee E,Corporate C, Country Co
WHERE
-- CONVERT(VARCHAR(19),E.RHFReceivedDate)<='June 6 2008 12:00AM
AND E.CorporateId=C.CorporateId
AND C.RegisterStatusId>=7
AND E.CardNo IS NOT NULL
-- AND E.CardStatus = 'L'
AND (E.CorporateId='IBM')
AND C.IsDeleted='0'
and E.EmpId='46565675'
AND E.NationalityCode = Co.CountryCode
ORDER BY C.CorporateId, E.EmpId
推荐答案
小于或等于日历控件中选定的日期...
Hi,
less than or equal to the selected date from calendar control...
DateAdd(dd,Datediff(dd,0,E.RHFReceivedDate),0) <= selected date from calendar control
请试试这个,并更新
Please try this, and update
因为您要存储时间组件以及日期组件,所以当您进行比较时需要进行比较
DateTime< (SelectedDate + 1天)
这将使您返回所选日期的所有条目,无论其时间成分如何。
Because you are storing a time component as well as a date component, when you do your comparison you need to do
DateTime < (SelectedDate + 1 day)
This will all you to return all of the entries for the selected date regardless of their time component.
E.RHFReceiveDate < '2008-06-29'
使用Date进行任何过滤之前只需将其转换为我们的安全
说
转换(日期,E.RHFReceiveDate)<转换(日期,'12 / 12/2012')
让我知道如果这样做
Before You do any filter using Date just Convert it for our safety
Say
Convert(date, E.RHFReceiveDate) < Convert(date, '12/12/2012')
let me knw if this works
这篇关于如何比较日期时间的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文