[英]Display data in sorting order based on arrived time with current date using LINQ query
public ViewResult Index1(DateTime? Startdate)
{
Startdate = DateTime.Now.Date;
DateTime Enddate = DateTime.Now;
string AM = "AM";
var value10 = from res in db.BookingArriveds where (res.BookingArrivedEnquiredDateTime >= Startdate && res.BookingArrivedEnquiredDateTime <= Enddate) orderby res.BookingArrivedEnquiredTime.Contains(AM) descending orderby res.BookingArrivedEnquiredTime descending select res;
return View(value10);
}
I have a one table. 我有一张桌子。 Table having a
arrivedtime
column with datatype is varchar
and another column arriveddate
. 具有数据类型的
arrivedtime
列的表为varchar
,另一列arriveddate
。 Now I want to sort arrivedtime
with current date. 现在,我想用当前日期对
arrivedtime
时间进行排序。
Data like this 像这样的数据
(03:30 PM,10:30 AM, 04:05 PM, 11:08 AM, 08:30 PM, 05:20 AM,12:08 AM )
with current date(18-03-2015).
Now I would like to sort the arrivedtime
like 现在,我想排序
arrivedtime
像
08:30 PM, 04:05 PM,03:30 PM,05:20 AM,10:30 AM, 12:08 AM.
I want display data in sorting the arrivedtime
using linq query based on current date. 我想在使用基于当前日期的linq查询对
arrivedtime
进行排序时显示数据。 How to write linq
query for sorting time? 如何编写
linq
查询排序时间?
您没有显示对象,但是我想在linq语句后附加一个简单的.OrderByDescending(x=>x.arrivedTime)
即可完成此工作。
Based on your comments to the Rober's answer, you are looking to order records based on timestamp for a given date. 根据对Rober答案的评论,您正在寻找根据给定日期的时间戳排序记录的方法。
BookingArriveds.Where(c=>DateTime.ParseExact(c.ArrivedDate,"yyyy-MM-dd", CultureInfo.InvariantCulture) == searchDate)
.OrderBy(c=>c.ArrivedTime);
You mary refer some Working Sample here. 您可以在这里参考一些工作示例 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.