how to search date within range in c Sharp dot net and mssql


On June 21

how to search date within range in c Sharp dot net and mssql


There are lots of time when it happens that you tried to search data within the date range
but you face issue such as data dont come out of certain time range, some time daata comes which is not even required,
here is the solution which you can use to get the perfect result for searching data perfectly within a range.


First at the code behind file in c# you need to format your date as follows.

 

String fromdata = DateTime.ParseExact(txtfromdate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);


String todate = DateTime.ParseExact(txttodate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);

 

This will resolve problems such as datetime not in correct format or invalid date format error given by sql.

now in SQL query do the following thind for selecting date within range

 

select * from table_name where createdate>=@fromdate and createdate<=convert(datetime, @todate + '23:59:59')

 

You may also like :

Basic steps to implement ASP dotnet MVC using Entity Framework Code First approach
SQL Query to Release lock on database
How to change URL withought page postback
Csharp Code to make call By connecting you phone to PC
BE Electronics ETC IT Computer Project Titles - Group 1
SQL Query to Split string by specific seperator
Simple Page Method in asp.net
Error 720 Resolution
Queries in LINQ to DataSet
BEWARE-XSS THIEVES ARE LOOKING FOR YOU
how to search date within range in c Sharp dot net and mssql

You may also like :





Responses