title: Getting date/time from DatePicker in swift
body: <p>I have created a separate class for Date Picker. </p>
  
  <pre><code>import UIKit
  
  protocol MYDatePickerViewControllerDelegate {
      func didFinishSelectingDate(selectedDate:NSDate)
  }
  
  class MYDatePickerViewController: UIViewController {
  
      @IBOutlet weak var containerView: UIView!
      @IBOutlet weak var datePicker: UIDatePicker!
      @IBOutlet weak var navigationBar: UINavigationBar!
  
      var datePickerDelegate : MYDatePickerViewControllerDelegate?
      var customTransitioningDelegate: MYFadeInFadeOutTransitioning? = MYFadeInFadeOutTransitioning()
  
      init(){
          super.init(nibName: "MyDatePickerViewController", bundle: NSBundle.mainBundle())
  
          transitioningDelegate = customTransitioningDelegate
          modalPresentationStyle = .Custom
      }
      convenience init(withSelectedDate date: NSDate) {
          self.init()
  
      }
      required init?(coder aDecoder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
      deinit {
          customTransitioningDelegate = nil
      }
  
      override func viewDidLoad() {
          super.viewDidLoad()
          setupViewControllerUI()
      }
  
      func setupViewControllerUI() {
          containerView.tag = kContainerViewTag
  
      }
  
      @IBAction func doneButtonTapped(sender: AnyObject) {
          datePickerDelegate?.didFinishSelectingDate(self.datePicker.date)
          print(self.datePicker.date)
          dismissViewControllerAnimated(true, completion: nil)
      }
      @IBAction func cancelButtonTapped(sender: AnyObject) {
          dismissViewControllerAnimated(true, completion: nil)
      }
  }
  </code></pre>
  
  <p>Which I am presenting from a different viewController as </p>
  
  <pre><code>let timePickerViewController = MYDatePickerViewController()
  presentViewController(timePickerViewController, animated: true, completion: nil)
  </code></pre>
  
  <p>it does present from bottom of screen as follows</p>
  
  <p><a href="https://i.stack.imgur.com/6ydul.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6ydul.png" alt="enter image description here"></a></p>
  
  <p>Now I am trying to get the selected date when user tap the done button on datePicker. For that i am trying to create a delegate and get selecetd date from there. but could not.
  I have implemneted the delegate of MYDatePickerViewController into my other ViewController as </p>
  
  <p>in my viewDidLoad</p>
  
  <pre><code>let datePicker = YASDatePickerViewController()
      datePicker.datePickerDelegate = self
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>func didFinishSelectingDate(selectedDate: NSDate) {
      print(selectedDate)
  }
  </code></pre>
  
  <p>But I am not getting the date, please guide me.</p>