title: Comparing timestamps in C#
body: <p>I'm rewriting some code from Java to C#. Unfortunately most of code was "hacked" so I'm just guessing how the code was written. Right now, I have to reproduce some inserts into data base..</p>
  
  <p>I got a little confused in the time stamp I have to insert. For example in current database the record is: <code>10-AUG-10 05.02.57.347694000 PM</code></p>
  
  <p><a href="http://i.stack.imgur.com/9RKUC.png" rel="nofollow">Values in current database</a></p>
  
  <p>In my code I was able to get something similar: <code>22-Aug-16 11.52.20.9857574 AM</code></p>
  
  <p>The idea of this code is to compare the timestamp created with the current one and perform some actions if the first one was created within the last 60 seconds.</p>
  
  <p>First question:</p>
  
  <p>How can I exactly reproduce <code>10-AUG-10 05.02.57.347694000</code>, I see that all the records have "000" at the end, do I need an if/else for that or is there any function to keep the last part 9 digits long?</p>
  
  <p>Second question:</p>
  
  <p>If it was only numbers, I know I can retrieve the values from the database and then compare, but since the format is: <code>10-AUG-10 05.02.57.347694000</code>, not really sure how to handle that part</p>
  
  <p>Any suggestions?</p>
  
  <hr>
  
  <p>SOLUTION:</p>
  
  <p>After reading some comments I got a better understanding on what to do with this issue. I decided to keep things simple and just create DateTime variables and then just use a subtract method in order to see how many minutes of difference there are between those two.</p>
  
  <p>Example:<br>
  DateTime guidTimestamp;    //8/25/2016 10:02:47 AM<br>
  DateTime currentTimestamp = DateTime.Now;</p>
  
  <pre><code>public int calculateMinutes(DateTime dt1, DateTime dt2)   
      {  
              int min = 0;  
          try     
          {      
              min = (int)((dt1 - dt2).TotalSeconds);    
          }    
          catch (Exception ex)    
          {    
              Debug.WriteLine("Exception - Date Time error: " + ex.Message);    
          }    
          return min;    
      } 
  </code></pre>