如何在asp.net中的两个日期之间获取记录
问题描述:
HI,
我希望在两个日期之间过滤数据...在我的数据库表中,我有Invoice_Date列。
我希望过滤日期,在数据库中它存储日期为'2013-10-06 00:00:00.000'。
可以任何人帮我解决这个问题
i want filter data between two dates... In my database table i have Invoice_Date column.
I want filter datewise and in database it is storing date as '2013-10-06 00:00:00.000'.
Can anyone help me to solve this
答
- Amit
试试这个:
Try this:
SELECT * FROM TableName1 WHERE MyDate BETWEEN '2011/02/25' AND '2011/02/27'
--or
SELECT * FROM TableName1 WHERE MyDate BETWEEN Date1 AND Date2
--Date1 and Date2 are two DateTimes
或者可以使用:
or can use:
SELECT Date,TotalAllowance FROM Calculation WHERE MyDate >'2011/02/25' AND MyDate <'2011/02/27'
--or
SELECT Date,TotalAllowance FROM Calculation WHERE MyDate > Date1 AND MyDate < Date2
--Date1 and Date2 are two DateTimes
select * from tableName where Invoice_Date between '2013-05-29 00:00:00.000' and '2013-05-30 00:00:00.000'
您始终可以使用Compare [ ^ ]方法。
您还可以使用TimeSpan
类过滤o数据。
但是,它总是建议尽可能对数据库进行过滤。
You can always do this on the front end using the Compare[^] method.
You can also useTimeSpan
class to filter out data.
However, its always recommended to do filtering on the database as far as possible.