title: How to convert Excel values to datetime format in C#
body: <p>I am trying to extract data from an Excel worksheet using Excel Interop.  The cells in the used range here contain Date/Time values.  I've managed to get the values as text, but how can I convert this to a numeric or Date/Time format that can be used in comparison operations?</p>
  
  <pre><code>using System;
  using Excel = Microsoft.Office.Interop.Excel;
  class Program
  {
      static void Main(string[] args)
      {
          Excel.Application xlApp;
          Excel.Workbook xlWorkBook;
          Excel.Worksheet xlWorkSheet;
          Excel.Range range;
  
          string str;
          int rCnt = 0;
          int cCnt = 0;
  
          xlApp = new Excel.Application();
          xlWorkBook = xlApp.Workbooks.Open("Wind_Speed.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
          xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
  
          range = xlWorkSheet.UsedRange;
  
          for (rCnt = 1; rCnt &lt;= range.Rows.Count; rCnt++)
          {
              for (cCnt = 1; cCnt &lt;= range.Columns.Count; cCnt++)
              {
                  // here I can get a string value... how to make it date/time
                  str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Text                                
                  Console.WriteLine(str);
                  Console.ReadLine();                       
              }
          }
  
          xlWorkBook.Close(true, null, null);
          xlApp.Quit();
  
          releaseObject(xlWorkSheet);
          releaseObject(xlWorkBook);
          releaseObject(xlApp);
  
          Console.ReadLine();
      }
  </code></pre>