Reputation:
This is the SQL Server sql statement that passed in the date and time (24 hour time)
declare @date varchar(10) = '2-15-2017'
declare @time varchar(2) = '11'
declare @timeExt varchar(3) = ':00'
--declare @mytime datetime = '2-15-2017 11:00'
declare @mytime datetime = @date + ' ' + @time + @timeExt
select * from [dbo].[QAList] Q
where q.CreatedDateTime between dateadd(hh,-1, @mytime) and @mytime
Then for Linq to SQL ( Entities) I was doing only Date , but i need to add in the time
string dateIn = "2-15-2017";
DateTime d = DateTime.Parse(dateIn);
Notice the .Where
var query = QALists
.Where (z => z.CreatedDateTime >= d )
.AsEnumerable()
.Select(z => new QAList()
{
Agent = z.Agent,
ClientName = z.ClientName,
Disposition = z.Disposition,
CallDate = z.Calldate,
Comment = z.Comment,
CreatedDateTime = z.CreatedDateTime,
CallLength = z.CallLength,
IdentityColumnId = z.IdentityColumnId,
Number = z.Number,
InboundCall = z.InboundCall,
OutboundCall = z.OutboundCall,
Status = z.Status,
QAListId = z.QAListId
}).ToList();
Upvotes: 0
Views: 46
Reputation: 205889
There is nothing LINQ specific in the question - just create two DateTime
variables containing the desired range (as you know, DateTime
data type contains both date and time):
var endTime = new DateTime(2017, 02, 15, 11, 00, 00);
var startTime = endTime.AddHours(-1);
then simply use them in the query criteria:
.Where (z => z.CreatedDateTime >= startTime && z.CreatedDateTime <= endTime)
Upvotes: 1