---
title: "Select all records between two dates using calendar"  
description: "Select all records between two dates using calendar"  
author: "marcel ethan"  
published: 2014-01-27  
updated: 2014-01-27  
canonical: https://www.mindstick.com/forum/1879/select-all-records-between-two-dates-using-calendar  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Select all records between two dates using calendar

I would like to [search record](https://www.mindstick.com/forum/33745/how-to-search-record-in-angular-js-in-asp-dot-net) by two dates, the two dates will be selected by a user via calendar. This is how I wrote the query:

public List<Staff> GetStaff([DateTime](https://www.mindstick.com/forum/12949/how-to-validate-if-a-datetime-field-is-not-null-empty) DateOne, DateTime DateTwo, string staffColourCode)

{

List<Staff> l= new List<Staff>();

[SqlConnection](https://www.mindstick.com/forum/1209/sqlconnection-sqlcommand-sqldatareader-idisposable) conn = new [connection](https://www.mindstick.com/articles/13012/what-makes-ethernet-connection-better-than-wifi) etc...

[SqlCommand](https://www.mindstick.com/forum/91/difference-between-sqlcommand-and-sqlcommandbuilder) [command](https://www.mindstick.com/blog/178/synchronous-and-asynchronous-command-execution-in-c-sharp-dot-net) = new SqlCommand("SELECT * FROM [TableName](https://www.mindstick.com/forum/34722/how-to-get-label-text-from-table-reference-on-database-based-on-tablename-and-fieldname) WHERE CAST(Time AS date) BETWEEN @Time and @Time", conn);

command.Parameters.AddWithValue("@Time", DateOne);

conn.Open();

SqlDataReader reader = command.ExecuteReader();

while (reader.Read())

{

Staff s= new Staff();

s.Name= reader["Name"].ToString();

etc...

l.Add(s);

}

conn.Close();

return l;

}

In my [database if](https://www.mindstick.com/forum/33472/restoring-a-database-if-it-was-not-detached-properly) i [replace](https://yourviews.mindstick.com/view/81330/cow-antibody-research-in-usa-a-step-ahead-to-replace-plasma-therapy) Time with some date then it works but how do i write a query that allows a users to select two dates and based on DateOne and DateTwo search the list of Staff who has a colour code of whatever a user selects e.g. Green, Yellow etc...

## Replies

### Reply by Pravesh Singh

Hi Marcel,

You need two different parameters:

```
SqlCommand command = new SqlCommand("SELECT * FROM
TableName " +                                     "WHERE
CAST(Time AS date) BETWEEN @DateOne and @DateTwo", conn);command.Parameters.AddWithValue("@DateOne",
DateOne);command.Parameters.AddWithValue("@DateTwo",
DateTwo);
```


---

Original Source: https://www.mindstick.com/forum/1879/select-all-records-between-two-dates-using-calendar

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
