Just like any other parameter ... Of course, it depends on how you make your data access, but if we accept SqlCommand, you just refer to the named parameter ( @fromDate/ @toDate) in TSQL and add the command SqlParameter(c .Value = theDate) to command:
DateTime end = DateTime.Today, start = end.AddDays(-7);
using (var conn = new SqlConnection(connectionString))
using (var cmd = conn.CreateCommand())
{
conn.Open();
cmd.Parameters.AddWithValue("@from", start);
cmd.Parameters.AddWithValue("@to", end);
cmd.CommandText = "SELECT COUNT(1) FROM [Users] WHERE LastSeen >= @from AND LastSeen < @to";
int count = (int) cmd.ExecuteScalar();
}
With LINQ etc. you will just use it in the request, i.e.
int count = db.Users.Count(user => user.LastSeen>=start && user.LastSeen<end);
, ; , SELECT blah VIEW .. ...