Hello,guys!
First of all,thank you for your reading this post!
Second,my question is how to carry out like SQL sentence "select * from table where sdate between @startdate and @enddate" by LinqDataSource.where
Be waiting for your answer!
LinqDataSource
We should be friends all over the world,then we can explore those worlds we have never been!
Dear anas,
Will it compare like string?
such as: sdate='05/01/2009',enddate='08/01/2008',and then (sdate<=enddate)=true, because the beginning "05"<"08".
if so, this is not the answer I want
We should be friends all over the world,then we can explore those worlds we have never been!
samova
Member
19 Points
39 Posts
LinqDataSource:How to filter by datetime?
Aug 29, 2009 03:19 PM|LINK
Hello,guys!
First of all,thank you for your reading this post!
Second,my question is how to carry out like SQL sentence "select * from table where sdate between @startdate and @enddate" by LinqDataSource.where
Be waiting for your answer!
LinqDataSource
anas
All-Star
73649 Points
7914 Posts
Moderator
Re: LinqDataSource:How to filter by datetime?
Aug 29, 2009 04:09 PM|LINK
DateTime startDate=...
DateTime endDate=...
LinqDataSource1.where=string.format("sdate >= {0} and sdate<={1}",startDate.ToString("MM/dd/yyyy"),endDate.ToString("MM/dd/yyyy"))
samova
Member
19 Points
39 Posts
Re: LinqDataSource:How to filter by datetime?
Aug 30, 2009 12:35 AM|LINK
Dear anas,
Will it compare like string?
such as: sdate='05/01/2009',enddate='08/01/2008',and then (sdate<=enddate)=true, because the beginning "05"<"08".
if so, this is not the answer I want
samova
Member
19 Points
39 Posts
Re: LinqDataSource:How to filter by datetime?
Aug 30, 2009 12:40 AM|LINK
But maybe it can work out if we change the string format into "yyyyMMDD",I will try it tomorrow.
Thanks a lot.
samova
Member
19 Points
39 Posts
Re: LinqDataSource:How to filter by datetime?
Aug 31, 2009 01:36 AM|LINK
Dear anas,
I think there is still a problem:how can I get sdate like YYYYMMDD ? Because sdate is "yyyy-MM-dd HH:mm:ss",the time part is no need!
anas
All-Star
73649 Points
7914 Posts
Moderator
Re: LinqDataSource:How to filter by datetime?
Aug 31, 2009 02:04 AM|LINK
You can pass a format for the .ToString() of the dataTime object.
LinqDataSource1.where=string.format("sdate >= {0} and sdate<={1}",startDate.ToString("yyyyMMdd"),endDate.ToString("yyyyMMdd"));
samova
Member
19 Points
39 Posts
Re: LinqDataSource:How to filter by datetime?
Aug 31, 2009 04:33 AM|LINK
Dear anas,
the following is the data:
How can I select those records which between 2009-5-5 and 2009-5-8? another say,how can I
set the sdate's format to be "yyyyMMdd" in oder to compare with startdate?
result:2009-05-05 00:06:02.000
samova
Member
19 Points
39 Posts
Re: LinqDataSource:How to filter by datetime?
Aug 31, 2009 07:01 AM|LINK
Hay,anas,
when I try this code:
LinqDataSource1.where= String.Format("submittime>={0} && submittime<={1}",Calendar1.SelectedDate.ToString("yyyy-MM-dd"),Calendar2.SelectedDate.AddDays(1).ToString("yyyy-MM-dd"));
It warns this error:异常详细信息: System.Web.Query.Dynamic.ParseException: 运算符“>=”与操作数类型“DateTime?”和“Int32”不兼容.
I hope you can read Chinese for I have no idea how to translate it
samova
Member
19 Points
39 Posts
Re: LinqDataSource:How to filter by datetime?
Nov 16, 2011 01:51 PM|LINK
I think the better way is to abandon linqdata