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:
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With