How to get datetime group by days via LINQ C# -


i have datatable contains data of whole month. want data group days via linq. have query need little change. day starts 7 o clock & ends @ next day 7 o clock. current query :

var query = dt.asenumerable()     .groupby(row => new     {         day = row.field<datetime>("dateandtime"),         code = row.field<string>("code"),         name = row.field<string>("name")     })     .select(g => new     {         name = g.key.name,         day = g.key.day,         code = g.key.code,         quantity = g.count()     }         ); 

dateandtime formate : 2014-01-02 05:26:10.567

how can data datatable group days of whole month ?

i want data 7 7. if month ends, last date data should data of next date upto 7 o clock.

just group day property of datetime value, after adjusting date/time accordingly 7 hours. of course, if have multiple months/years involved, give odd results, but...

.groupby(row => new {     day = row.field<datetime>("dateandtime").addhours(-7).day,     code = row.field<string>("code"),     name = row.field<string>("name") }) 

(note: you'll need make sure original query find data month takes 7 hour shift account. also, if 7 hour shift due time zones, there better options.)


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -