0

Should the following always match:

if(mydbrecord.DateField.Date == DateTime.Now.Date)
{...}

where mydbrecord date is the current day? I'm retrieving mydbrecord through linq-sql.

mydbrecord.DateField.Date is in the format '2013-12-19 00:00:00.000'.

6
  • Do your mydbrecord.DateField.Date value is Date only or it includes time? Commented Dec 20, 2013 at 2:09
  • I've updated the OP with the answer. Commented Dec 20, 2013 at 3:21
  • 1
    Ok your comparison won't be equal since current date have time value Commented Dec 20, 2013 at 3:22
  • If I do Convert.ToDatetime('2013-12-19 00:00:00.000'), they do equal. Commented Dec 20, 2013 at 3:24
  • see my posted answer and try. Commented Dec 20, 2013 at 3:25

1 Answer 1

1

Do it like this

if(mydbrecord.DateField.Date.ToString("yyyy/MM/dd") == DateTime.Now.Date.ToString("yyyy/MM/dd"))
{...}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.