9 个解决方案
#1
DataTime.Now.ToString("yyyy-MM-dd");//获取日期,根据这个group by即可
#2
要一个一个取出来转换么,不能直接在linq语句里写啊,有7万多行呢
#3
http://www.cnblogs.com/kezhiping/p/3873746.html
自己搜索相关的知识吧~~~
目标是调用数据库的日期函数
自己搜索相关的知识吧~~~
目标是调用数据库的日期函数
#4
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<Student> students = new List<Student>()
{
new Student(){ ID = 1 , Name ="guwei1", BirthDay=DateTime.Now.AddHours(-11), Phone="123456781"},
new Student(){ ID = 2 , Name ="guwei2", BirthDay=DateTime.Now.AddHours(2).AddDays(2), Phone="123456782"},
new Student(){ ID = 3 , Name ="guwei3", BirthDay=DateTime.Now.AddHours(-13), Phone="123456783"},
new Student(){ ID = 4 , Name ="guwei4", BirthDay=DateTime.Now.AddHours(4).AddDays(4), Phone="123456784"},
};
var result = from p in students
group p by p.BirthDay.ToString("yyyy-MM-dd") into g
let q = students.Where(x => x.BirthDay.ToString("yyyy-MM-dd") == g.Key)
select new
{
ID = q.Select(y => y.ID),
Name = q.Select(y => y.Name),
BirthDay = g.Key,
Phone = q.Select(y => y.Phone),
};
foreach (var item in result)
{
Console.WriteLine("ID:{0} Name:{1} BirthDay:{2} Phone:{3}",
string.Join(",", item.ID),
string.Join(",", item.Name),
item.BirthDay,
string.Join(",", item.Phone));
}
}
}
public class Student
{
public int ID { get; set; }
public string Name { get; set; }
public DateTime BirthDay { get; set; }
public string Phone { get; set; }
}
}
#5
from d in list
group d by d.Day.Date into g
select g
#6
datetime也可以groupby
#7
楼上各位都想简单了 linq to object 当然可以这么做
但linq to ef 就不可以了
因为转换成sql的时候 不认识 date 和 ToString("yyyy-MM-dd")
但linq to ef 就不可以了
因为转换成sql的时候 不认识 date 和 ToString("yyyy-MM-dd")
#8
我的是datatable的,应该可以,我仿照4L的看看
#9
DataTable dt = new DataTable();
var query = from r in dt.AsEnumerable()
group r by r.Field<DateTime>("date").Date into g
select g;
DataTable的
#1
DataTime.Now.ToString("yyyy-MM-dd");//获取日期,根据这个group by即可
#2
要一个一个取出来转换么,不能直接在linq语句里写啊,有7万多行呢
#3
http://www.cnblogs.com/kezhiping/p/3873746.html
自己搜索相关的知识吧~~~
目标是调用数据库的日期函数
自己搜索相关的知识吧~~~
目标是调用数据库的日期函数
#4
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<Student> students = new List<Student>()
{
new Student(){ ID = 1 , Name ="guwei1", BirthDay=DateTime.Now.AddHours(-11), Phone="123456781"},
new Student(){ ID = 2 , Name ="guwei2", BirthDay=DateTime.Now.AddHours(2).AddDays(2), Phone="123456782"},
new Student(){ ID = 3 , Name ="guwei3", BirthDay=DateTime.Now.AddHours(-13), Phone="123456783"},
new Student(){ ID = 4 , Name ="guwei4", BirthDay=DateTime.Now.AddHours(4).AddDays(4), Phone="123456784"},
};
var result = from p in students
group p by p.BirthDay.ToString("yyyy-MM-dd") into g
let q = students.Where(x => x.BirthDay.ToString("yyyy-MM-dd") == g.Key)
select new
{
ID = q.Select(y => y.ID),
Name = q.Select(y => y.Name),
BirthDay = g.Key,
Phone = q.Select(y => y.Phone),
};
foreach (var item in result)
{
Console.WriteLine("ID:{0} Name:{1} BirthDay:{2} Phone:{3}",
string.Join(",", item.ID),
string.Join(",", item.Name),
item.BirthDay,
string.Join(",", item.Phone));
}
}
}
public class Student
{
public int ID { get; set; }
public string Name { get; set; }
public DateTime BirthDay { get; set; }
public string Phone { get; set; }
}
}
#5
from d in list
group d by d.Day.Date into g
select g
#6
datetime也可以groupby
#7
楼上各位都想简单了 linq to object 当然可以这么做
但linq to ef 就不可以了
因为转换成sql的时候 不认识 date 和 ToString("yyyy-MM-dd")
但linq to ef 就不可以了
因为转换成sql的时候 不认识 date 和 ToString("yyyy-MM-dd")
#8
我的是datatable的,应该可以,我仿照4L的看看
#9
DataTable dt = new DataTable();
var query = from r in dt.AsEnumerable()
group r by r.Field<DateTime>("date").Date into g
select g;
DataTable的