8,497
社区成员
发帖
与我相关
我的任务
分享
public class User
{
public int id;
public string name;
public DateTime cardTime;
}
static List<User> list = new List<User>()
{
new User(){id=2,name="Jay",cardTime=DateTime.Parse("2017-05-02 03:00:00")},
new User(){id=1,name="Jay",cardTime=DateTime.Parse("2017-05-02 04:00:00")},
new User(){id=1,name="Jay",cardTime=DateTime.Parse("2017-05-03 04:00:00")},
new User(){id=1,name="Jay",cardTime=DateTime.Parse("2017-05-03 12:00:00")},
new User(){id=1,name="Jay",cardTime=DateTime.Parse("2017-05-04 23:00:00")},
new User(){id=1,name="Jay",cardTime=DateTime.Parse("2017-05-04 07:00:00")},
new User(){id=1,name="Jay",cardTime=DateTime.Parse("2017-05-05 04:00:00")},
};
static void Main()
{
var groups = list.GroupBy(x => x.cardTime.Hour > 6 ? x.cardTime.ToString("yyyy-MM-dd") : x.cardTime.AddDays(-1).ToString("yyyy-MM-dd"));
foreach (var group in groups)
{
Console.WriteLine(string.Format("下列时间属于:{0}组", group.Key));
foreach (var item in group)
{
Console.WriteLine(item.cardTime);
}
Console.WriteLine();
}
}
static List<User> list = new List<User>()
{
new User(){id=2,name="Jay",cardTime=DateTime.Parse("2017-05-02 03:00:00")},
new User(){id=1,name="Jay",cardTime=DateTime.Parse("2017-05-02 04:00:00")},
new User(){id=1,name="Jay",cardTime=DateTime.Parse("2017-05-03 04:00:00")},
};
static void Main(string[] args)
{
DateTime start=new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day-1,6,0,0);
DateTime end=new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,6,0,0);
var q = list.Where(x => x.cardTime >= start && x.cardTime < end).ToList();
Console.ReadLine();
}
[/quote]
大哥,这个是where判断,那分组呢?是吧分组的条件按你where里面的写的就可以吗static List<User> list = new List<User>()
{
new User(){id=2,name="Jay",cardTime=DateTime.Parse("2017-05-02 03:00:00")},
new User(){id=1,name="Jay",cardTime=DateTime.Parse("2017-05-02 04:00:00")},
new User(){id=1,name="Jay",cardTime=DateTime.Parse("2017-05-03 04:00:00")},
};
static void Main(string[] args)
{
DateTime start=new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day-1,6,0,0);
DateTime end=new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,6,0,0);
var q = list.Where(x => x.cardTime >= start && x.cardTime < end).ToList();
Console.ReadLine();
}
select * from [dbo].[PO_Shipment]
where S_CreateDate
between (CONVERT(varchar(100), DATEAdd(dd,-1,GETDATE()), 23)+' 06:00:00')
and (CONVERT(varchar(100), GETDATE(), 23)+' 06:00:00')
--2017-05-02 06:00:00
select (CONVERT(varchar(100), DATEAdd(dd,-1,GETDATE()), 23)+' 06:00:00')
--2017-05-03 06:00:00
select (CONVERT(varchar(100), GETDATE(), 23)+' 06:00:00')