0

I have asp net core application with MongoDB.and I'm saving the date in the format of [dd/MM/yyyy]

{"CreatedDate",DateTime.Now.Date.ToString("dd/MM/yyyy") } 

whereas CreatedDate is field in the MongoDB . and i have to compare the saved date with filterDate that i'm sending. What's the best way to compare the dates with MongoDB?

6
  • 1
    Have you tried something? Put it in Quesion Commented Oct 23, 2019 at 8:44
  • Have you checked this link stackoverflow.com/questions/31071999/date-comparison-in-mongodb Commented Oct 23, 2019 at 8:49
  • @Sushantyelpale i have tried wirh MongoDbBuilder like, builder.Where(s => (s.CreatedDate != null && s.CreatedDate >= from_date) but there is error....Not able to compare Commented Oct 23, 2019 at 8:51
  • i have already checked the link you have provided[stackoverflow.com/questions/31071999/… think its for cmd ,but not with C# Commented Oct 23, 2019 at 8:56
  • Is your filterDate in the same format as your CreatedDate? A dd/MM/yyyy string? Commented Oct 23, 2019 at 8:59

1 Answer 1

0

Do not store date object as string, you cannot compare to any date variable by this way. Yo should insert your dates like

{"CreatedDate", new Date("2017-03-24T17:00:00.832Z")} or {"CreatedDate", new Date()} 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.