title: Why is my date comparison not working?
body: <p>We have a requirement that if a user has forgotten their password, they should request and receive a <strong>forgotten password</strong> link via email to reset their password.</p>
  
  <p>I am using a date time comparison along with a  token in form of a unique code to ensure a certain level of security.</p>
  
  <p>As soon as they receive an email link to reset the password and the user clicks on the link to reset password, the user is presented with a screen to reset password. This is working great so far.</p>
  
  <p>What I am having problems with is when a user clicks on the email link to reset their password more than 24 hours after the email with link was sent, they get a blank page.</p>
  
  <p>We want the user to get a page that says, <strong>Reset password link has expired. It was for one time use only</strong> but that message is not visible.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Below is the code I am using:</p>
  
  <pre><code>If dr.HasRows Then
      Dim dtCreate As DateTime = DateTime.Now
      Dim dtNow As DateTime = DateTime.Now
      Dim dtExp As DateTime = dtCreate.AddDays(1)
      If dtNow &gt; dtExp Then
          ResetPwdPanel.Visible = False
          Expired.Visible = True
      Else
          ResetPwdPanel.Visible = True
          Expired.Visible = False
          lblExpired.Text = "Reset password link has expired. It was for one time use only"
          Return
  
      End If
  End If
  </code></pre>
  
  <p>'Markup:</p>
  
  <pre><code>&lt;form id="form1" runat="server"&gt;
  
  &lt;div&gt;
  
  &lt;asp:Panel ID="ResetPwdPanel" runat="server" Visible="false" &gt;
  
  &lt;fieldset style="width:400px"&gt;
  
  &lt;legend&gt;Reset Password&lt;/legend&gt;    
  
  &lt;table&gt;
  
  &lt;tr&gt;
  
  &lt;td&gt;New password: &lt;/td&gt;&lt;td&gt;
      &lt;div class="input text"&gt; 
      &lt;asp:TextBox ID="txtNewPwd" style="width:150px;" TextMode="Password" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/div&gt;&lt;br /&gt;
  
      &lt;asp:RequiredFieldValidator ID="rfvNewPwd" runat="server" 
  
          ControlToValidate="txtNewPwd" Display="Dynamic" 
  
          ErrorMessage="Please enter new password" ForeColor="Red" SetFocusOnError="True"&gt;&lt;/asp:RequiredFieldValidator&gt;
  
      &lt;/td&gt;
  
  &lt;/tr&gt;
  
  &lt;tr&gt;
  
  &lt;td&gt;Confirm Passsword: &lt;/td&gt;&lt;td&gt;
  &lt;div class="input text"&gt; 
      &lt;asp:TextBox ID="txtConfirmPwd" style="width:150px;" TextMode="Password" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/div&gt;&lt;br /&gt;
  
      &lt;asp:RequiredFieldValidator ID="rfvConfirmPwd" runat="server" 
  
          ControlToValidate="txtConfirmPwd" Display="Dynamic" 
  
          ErrorMessage="Please re-enter password to confirm" ForeColor="Red" 
  
          SetFocusOnError="True"&gt;&lt;/asp:RequiredFieldValidator&gt;
  
      &lt;asp:CompareValidator ID="cmvConfirmPwd" runat="server" 
  
          ControlToCompare="txtNewPwd" ControlToValidate="txtConfirmPwd" 
  
          Display="Dynamic" ErrorMessage="Password didn't match" ForeColor="Red" 
  
          SetFocusOnError="True"&gt;&lt;/asp:CompareValidator&gt;
  
      &lt;/td&gt;
  
  &lt;/tr&gt;
  
  &lt;tr&gt;
  
  &lt;td&gt;
  
      &amp;nbsp;&lt;/td&gt;&lt;td&gt;
  
      &lt;asp:Button ID="btnChangePwd" runat="server" Text="Change Password" 
  
              onclick="btnChangePwd_Click" /&gt;&lt;/td&gt;
  
  &lt;/tr&gt;
  
      &lt;tr&gt;
  
          &lt;td colspan="2"&gt;
  
              &lt;asp:Label ID="lblStatus" runat="server" Text=""&gt;&lt;/asp:Label&gt;
  
          &lt;/td&gt;
  
      &lt;/tr&gt;
  
  &lt;/table&gt;
  
  &lt;/fieldset&gt;        
  
  &lt;/asp:Panel&gt;
  
   &lt;asp:panel ID="Expired" runat="server"&gt;
     &lt;asp:Label ID="lblExpired" runat="server" Text="" style="color: #FF0000"&gt;&lt;/asp:Label&gt;&lt;/asp:panel&gt;
  </code></pre>
  
  <p>
      
  We have two panel controls. One that shows reset password controls (this works) whilst the other shows the reset password link expiration message (this does not work).</p>