Getting all values of a particular column by comparing Month part of DateTime field in SQL using Linq.
Fetch the month of date time field using the Value property in Linq. Then get the Month of it as: f.ForDate.Value.Month
e.g., the following query will get all start time as an array of String where the Month of ForDate field in Table FPCTimeMaster matches the Month of DateTime field timeMasterDate.
string[] startTimes = context.FPCTimeMasters.Where(f =>f.ForDate.Value.Month == timeMasterDate.Month && f.ChannelId == channelID ).Select(s => s.StartTime).ToArray();
Fetch the month of date time field using the Value property in Linq. Then get the Month of it as: f.ForDate.Value.Month
e.g., the following query will get all start time as an array of String where the Month of ForDate field in Table FPCTimeMaster matches the Month of DateTime field timeMasterDate.
string[] startTimes = context.FPCTimeMasters.Where(f =>f.ForDate.Value.Month == timeMasterDate.Month && f.ChannelId == channelID ).Select(s => s.StartTime).ToArray();
No comments:
Post a Comment