Click here to Skip to main content
15,907,395 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
var _tol = from to in ddc.tbl_LeadAssigns
                          where to.ToDate == DateTime.Today && to.UserId == new Guid(sID)
                          select to;
               foreach (var cnt in _tol)
               {
                   todayCount = todayCount + Convert.ToInt32(cnt.TotalLead);
               }
               lblToday.Text = todayCount.ToString();
Posted
Comments
Mahendra.p25 9-May-11 8:15am    
what is the error
R. Giskard Reventlov 9-May-11 8:17am    
Last week.
Vineet_2109 9-May-11 8:18am    
In above query, i want today's lead from column "totalLead" and add all lead.
if i change code in query and put "where to.Todate < DateTime.Today" it return previous lead and add all lead. so how can i retrieve compare today date.

The problem is probably that the DateTime value you retrieve from the database will have a time on it, so the comparison will never succeed.
Try:
where to.ToDate.Today == DateTime.Today && to.UserId == new Guid(sID)
That may fix it. If it doesn't then we will need a bit more info.
 
Share this answer
 
Comments
Vineet_2109 9-May-11 8:42am    
where to.ToDate.Today this wont happen as it LINQ database entity
Wonde Tadesse 9-May-11 22:14pm    
It doesn't work with direct == operator. :(. That happen usually the database time value will not match to the current date time value. I know that you already stated but the example you gave doesn't work.
I will answer your question based on two assumption.
1.If your table contains non nullable value of ToDate column.If so you have to use ToDate.Value
2.If you concerned only about Month,Day and Year values of the ToDate column. Not hour, minute and second values. If so you can format based on these values.

If we agree on this, the following code will properly select date value from your linq query

C#
var query = from to in ddc.tbl_LeadAssigns
                   select new { formatedDate = to.ToDate.Month + "/" + to.ToDate.Day + "/" + to.ToDate.Year, to.UserId };

       var _tol = from to in query
                  where to.formatedDate.Equals(DateTime.Now.ToShortDateString())
                  select to;
              foreach (var cnt in _tol)
              {
                  todayCount = todayCount + Convert.ToInt32(cnt.TotalLead);
              }
              lblToday.Text = todayCount.ToString();


Again there are a lot of assumption that I left, like culture and more.
 
Share this answer
 
If you save long date time in your database ,you can check the following code for only one day

C#
var _tol = "from to in ddc.tbl_LeadAssigns
           where to.ToDate > "+  DateTime.Today + " &&"+ "to.ToDate < "+ DateTime.Today.AddDays(1) +" <pre lang="sql">&& to.UserId == new Guid(sID)
                          select to;
               foreach (var cnt in _tol)
               {
                   todayCount = todayCount + Convert.ToInt32(cnt.TotalLead);
               }
               lblToday.Text = todayCount.ToString();



Best Regard ,
Theingi Win
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900