Get records in particular date range

c#

Solution

To create a DateTime representing 60 days ago use this:

 DateTime.Now.AddDays(-60)

Note that it would probably be a better idea to send this query to the database rather than filtering on the client.

Problem

I have a column in database `DateCreated` that shows the creation date. Now I want to filter records depending on the date range selected. For example: - created within 60 days - created within month - etc... I have a variable `dateCreated` that shows me what the user has selected as the range, i.e. whether it is created within 60 days, created within year, and so on. ``` DateTime CurrTime = DateTime.Now; if (Program.DateCreated <= DateTime.Now - 60) { //code to add the record goes here.. } ``` But the above code wont work. What would be the syntax to get the records within a particular range?

Original source