c# - How do I get the hour part with SqlFunctions.DateName -


i have query need compare 24hour format hour of datetime property in entity 24hour time string

example:

var time = "14:00"; var results = db.table.where(item =>      sqlfunctions.datename("hh:mm", item.datetimeproperty) == time); 

although throws following

{"'hh:mm' not valid value datepart argument in 'sqlserver.datename' function."}

how can convert datetime property 24hour-clock time sqlfunctions?

your use of sql server's datename function not quite right. please try this:

var time = "14:00"; var hour = int32.parse(time.substring(0, 2)); var minute = int32.parse(time.substring(3, 2)); var results = db.table.where(item =>     sqlfunctions.datename("hh", item.datetimeproperty) == hour &&     sqlfunctions.datename("n", item.datetimeproperty) == minute); 

also see msdn page.


Comments