Querying between two date values in asp.net mvc5 -


i have treatmentdate column in database dates treated patients submitted. if need generate report of total sum between january 01 2015 , jan 30 2015 particular company, how construct query.

below have done , i'm having errors

            var treatmentsum = (from s in db.treatments                                 (s.companyid == companyid)                                 s.treatmentdate >= fromdate && s.treatmentdate <= todate                                 select s.amount).sum();                             viewbag.treatmentsum = treatmentsum; 

here's treatment date column want search through. enter image description here

your guidance highly appreciated.

you didn't post error message. trying compare strings using <= , >= , instead try handle of date , time variable datetime properties. here's piece of code linq expression:

datetime fromdate= convert.todatetime("04/20/2015"); datetime todate= convert.todatetime("04/28/2015"); viewbag.treatmentsum = getalltreatments. where(c=>convert.todatetime(c.treatmentdate)>=fromdate && convert.todatetime(c.treatmentdate)<=todate). sum(c=>c.amount);  

also here's link demo specific problem : https://dotnetfiddle.net/1a50hi


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -