title: compare between dates in .net
body: <p>I want to compare between two dates.
  From both the dates, I am fetching only date component using <code>ToShortDateString()</code>, as shown below. Now the problem is when I'm comparing the two dates. Its throwing error -- </p>
  
  <blockquote>
    <p>"Operator >= can't be applied to operands of type string and string."</p>
  </blockquote>
  
  <pre><code>DateTime srtdate = Convert.ToDateTime(allitem["StartDate"].Text.ToString());
  DateTime srtdate = Convert.ToDateTime(allitem["StartDate"].Text.ToString());
  
   (DateTime.Now.ToShortDateString() &gt;= srtdate.ToShortDateString()) 
  </code></pre>
  
  <p>I need to compare <strong>date component only</strong>, NOT date and time together.</p>
  
  <p>Please suggest what is the alternative way. Thanks</p>
  
  <p><em><strong>To JON:-</em></strong></p>
  
  <p>(I went tyhrough all what you explained and understood  hopefully what the point actually you trying to make. Just to clarify more and make a last check I ll show an example.)
  I have an web interface, where I give a start date and end date for a XYZ name (Note I can enter only date here, not time). </p>
  
  <blockquote>
    <p><strong>Start Date - 22-Feb-2012</strong> AND <strong>End Date - 22-Feb-2012</strong></p>
  </blockquote>
  
  <p>Now in back end (code), if Start date and End date is same as Current date OR current date is in between start and end date, I want a ACTIVE flag set or else not. I give the condition as this:-</p>
  
  <pre><code>if ((DateTime.Today &gt;= strdate.Date) &amp;&amp; (DateTime.Today &lt;= enddate.Date))
                      lblCondition.Text = "CHECKED";
  </code></pre>
  
  <p>Now when I debug the code,</p>
  
  <blockquote>
    <p>Both <strong>DateTime.Today</strong> and <strong>strdate.Date</strong> gives the value as 2/22/2012 12:00:00 AM.</p>
  </blockquote>
  
  <p>So, Jon my question is:- Would 'today' and 'date' work as per mentioned requirement, where only date component used. I hope it would.</p>
  
  <p>Thanks a lot for all your explanantion before.</p>