如何返回今天在C#或SQL Server中订购的数据?

时间:2021-03-09 23:08:44

I have table in my SQL Server database called OrderDetail which stores the order data. I have a column in this table called OrderDate which stores the date and time information about the orders.

我在我的SQL Server数据库中有一个名为OrderDetail的表,它存储订单数据。我在这个表中有一个名为OrderDate的列,它存储有关订单的日期和时间信息。

I want to retrieve all those orders from OrderDetail table which were created today.

我想从今天创建的OrderDetail表中检索所有这些订单。

My scenario is that I want to make a button which will click by admin at night to see that how many orders are done today?

我的情况是我想制作一个按钮,管理员会在晚上点击,看看今天有多少订单?

Any help regard to this will be appreciated.

任何有关这方面的帮助将不胜感激。

4 个解决方案

#1


0  

try something like this:

尝试这样的事情:

SELECT A.OrderID, ...
FROM OrderDetail as 'A' INNER JOIN OrderDate as 'B' ON 
        A.OrderID = B.OrderID
WHERE B.DateOfOrder BETWEEN '5/20/2011 00:00:00' AND '5/20/2011 23:59:59'

I assumed that you have ID in your OrderDetail and that ID is the same in the OrderDate table.

我假设您的OrderDetail中有ID,而OrderDate表中的ID是相同的。

#2


0  

Try with this query:

尝试使用此查询:

SELECT * FROM OrderDetails
WHERE CONVERT(VARCHAR(10), OrderDate , 101)=CONVERT(VARCHAR(10),GETDATE(),101);

#3


0  

SELECT * FROM OrderDetail 
WHERE DATEADD(dd, 0, DATEDIFF(dd, 0, OrderDate)) = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))

DATEADD(dd, 0, DATEDIFF(dd, 0, OrderDate) << this is to get rid of the time portion.

DATEADD(dd,0,DATEDIFF(dd,0,OrderDate)< <这是摆脱时间部分。< p>

#4


0  

select * from OrderDetails
where cast(OrderDate as date) = '2012-03-11'

If you want to extract the date part from a DateTime in C# then do this:

如果要从C#中的DateTime中提取日期部分,请执行以下操作:

DateTime dt = DateTime.Now;
DateTime d = dt.Date;
//or if you want a string
string dStr = dt.ToString("yyyy-MM-dd");

#1


0  

try something like this:

尝试这样的事情:

SELECT A.OrderID, ...
FROM OrderDetail as 'A' INNER JOIN OrderDate as 'B' ON 
        A.OrderID = B.OrderID
WHERE B.DateOfOrder BETWEEN '5/20/2011 00:00:00' AND '5/20/2011 23:59:59'

I assumed that you have ID in your OrderDetail and that ID is the same in the OrderDate table.

我假设您的OrderDetail中有ID,而OrderDate表中的ID是相同的。

#2


0  

Try with this query:

尝试使用此查询:

SELECT * FROM OrderDetails
WHERE CONVERT(VARCHAR(10), OrderDate , 101)=CONVERT(VARCHAR(10),GETDATE(),101);

#3


0  

SELECT * FROM OrderDetail 
WHERE DATEADD(dd, 0, DATEDIFF(dd, 0, OrderDate)) = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))

DATEADD(dd, 0, DATEDIFF(dd, 0, OrderDate) << this is to get rid of the time portion.

DATEADD(dd,0,DATEDIFF(dd,0,OrderDate)< <这是摆脱时间部分。< p>

#4


0  

select * from OrderDetails
where cast(OrderDate as date) = '2012-03-11'

If you want to extract the date part from a DateTime in C# then do this:

如果要从C#中的DateTime中提取日期部分,请执行以下操作:

DateTime dt = DateTime.Now;
DateTime d = dt.Date;
//or if you want a string
string dStr = dt.ToString("yyyy-MM-dd");