ramco1917 says:
I want to add 1 Hr to Vtime and store in another variable say toTime.
To add 1 Hour you need to use AddHours method.
Then convert to time to DateTime and use the from and to time in the linq where clause.
Refer below example.
HTML
<asp:GridView ID="gvEmployees" runat="server" >
</asp:GridView>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGridView();
}
}
private void BindGridView()
{
string mDate = "2022-07-18";
string mTime = "10:25";
int id = 1;
string vDate = Convert.ToDateTime(mDate).ToString("dd-MM-yyyy");
DateTime vTime = Convert.ToDateTime(mTime);
DateTime toTime = Convert.ToDateTime(mTime).AddHours(1);
using (NORTHWINDEntities entities = new NORTHWINDEntities())
{
var results = (from emp in entities.Employees
where emp.EmployeeID == id && (emp.BirthDate >= vTime && emp.BirthDate <= toTime)
select emp);
gvEmployees.DataSource = results.ToList();
gvEmployees.DataBind();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindGridView()
End If
End Sub
Private Sub BindGridView()
Dim mDate As String = "2022-07-18"
Dim mTime As String = "10:25"
Dim id As Integer = 1
Dim vDate As String = Convert.ToDateTime(mDate).ToString("dd-MM-yyyy")
Dim vTime As DateTime = Convert.ToDateTime(mTime)
Dim toTime As DateTime = Convert.ToDateTime(mTime).AddHours(1)
Using entities As NORTHWINDEntities = New NORTHWINDEntities()
Dim results = (From emp In entities.Employees
Where emp.EmployeeID = id AndAlso (emp.BirthDate >= vTime AndAlso emp.BirthDate <= toTime)
Select emp)
gvEmployees.DataSource = results.ToList()
gvEmployees.DataBind()
End Using
End Sub
Screenshot