Home Compare dates linq c#
Reply: 0

Compare dates linq c#

user11685 Published in September 19, 2018, 6:44 pm

This question already has an answer here:

  • How to compare only date components from DateTime in EF? 15 answers

I cant seem to get my query to check the database if a date exists. Please help.

 DateTime value = new DateTime(2018, 10, 26);
 item = await table.Where(todoItem => todoItem.Date == value.date)

I think the format which c# writes their dates and SQL are different so it cant find a match. Also the database is correctly linked to the app as I am able to query other rows in the same table.

share|improve this question

marked as duplicate by Igor c# StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var $hover = $(this).addClass('hover-bound'), $msg = $hover.siblings('.dupe-hammer-message'); $hover.hover( function() { $hover.showInfoMessage('', { messageElement: $msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Nov 13 '17 at 20:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 4
    Include the structure of your table – Steven Wexler Nov 13 '17 at 20:16
  • 1
    todoItem.Date might be including a time that value is not including. It's often a good idea to force both dates to midnight for comparison. – theGleep Nov 13 '17 at 20:17
  • @StevenWexler it works perfectly if I query the name for instance todoItem.Date == "Steven" so Im unsure as to why it isnt working. The data type ive given the 'date' field is DATE – mick1996 Nov 13 '17 at 20:22
  • 1
    @theGleep forcing row dates to midnight is horrible for performance (basically can't use indexes), basically causes the sql to be non-sargable. – Erik Philips Nov 13 '17 at 20:22
  • 1
    @JohnDoe just include the table structure so there's no ambiguity. – Steven Wexler Nov 13 '17 at 20:24

3 Answers 3

active oldest votes
up vote -1 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.253083 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO