title: WPF 2015 Visual Studio DatePicker using C#
body: <p>I have a problem regarding the DatePicker from the ToolBox. I'm trying to create a program in WPF for a user to choose two dates from two DatePickers, and based on these dates determine the amount of days between them.</p>
  
  <p>Online I found another typ of tool called DateTimePicker, which seems easier to use. However, this is not included in my ToolBox so I'm forced to use the DatePicker-class. </p>
  
  <p>So far my cs-code looks like below.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  
  namespace DateDifference
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
  
  
          }
  
  
          public static object RadDatePickerStart { get; private set; }
  
          private void button_Click(object sender, RoutedEventArgs e)
          {
  
  
          }
  
  
          private void startDate_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
          {
              // ... Get DatePicker reference.
              var picker = sender as DatePicker;
  
              // ... Get nullable DateTime from SelectedDate.
              DateTime? date = picker.SelectedDate;
  
              if (date == null)
              {
                  // ... A null object.
                  this.Title = "No date";
              }
              else
              {
                  // ... No need to display the time.
                  this.Title = "Program for calculating difference between dates";
                  textBoxResult.Text = date.Value.ToShortDateString();
  
              }
          }
  
          private void endDate_SelectedDateChanged_1(object sender, SelectionChangedEventArgs e)
          {
              // ... Get DatePicker reference.
              var picker = sender as DatePicker;
  
              // ... Get nullable DateTime from SelectedDate.
              DateTime? date = picker.SelectedDate;
  
              if (date == null)
              {
                  // ... A null object.
                  this.Title = "No date";
              }
              else
              {
                  // ... No need to display the time.
                  this.Title = "Program for calculating difference between dates";
                  textBoxResult.Text = date.Value.ToShortDateString();
  
              }
          }
      }
  }
  </code></pre>
  
  <p>So my question is how to get the difference in days with this DatePicker-class?</p>
  
  <p>Best regards!</p>