Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to compare dates in C# /sql server.

Posted on 2012-03-11
5
457 Views
Last Modified: 2012-03-12
I have date at back end in 3/1/2012 12:00:00 AM
And from front end the date of entry is: 1-March-2012

string s = "select * from mstbt where feeddate>='" + Convert.ToDateTime(txtfdate.Text.Trim()) + "' and feeddate<='" + Convert.ToDateTime(txttdate.Text.Trim()) + "' order by 1 desc,2 desc,3 asc";
0
Comment
Question by:searchsanjaysharma
5 Comments
 
LVL 9

Accepted Solution

by:
suvmitra earned 500 total points
ID: 37708509
select someColumn from someTable where DATEDIFF(seconds,GETDATE(),someDate) > ElapsedTimeColumn


msdn: http://msdn.microsoft.com/en-us/library/system.datetime.aspx
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 37708516
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 37708627
To play safe, you should convert to date, then format this to the correct string format for SQL Server:
string sqlfdate = "\'" + DateTime.Parse(txtfdate.Text.Trim()).ToString("yyyy-MM-dd") + "\'";
string sqltdate = "\'" + DateTime.Parse(txttdate.Text.Trim()).ToString("yyyy-MM-dd") + "\'";
s = "select * from mstbt where feeddate between " + sqlfdate + " and " + sqltdate + " order by 1 desc,2 desc,3 asc";

Open in new window

/gustav
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37713109
Thnx
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 37713337
??
There was no ElapsedTimeColumn field but a start and an end date.

/gustav
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question