title: Get Time From manual datePicker According to selected date swift
body: <p><a href="https://i.stack.imgur.com/9qDIH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9qDIH.png" alt="enter image description here"></a>I have two fields called date and time. I am creating datepicker by using this code</p>
  
  <pre><code>var selectedDate : NSDate!
  func date_picker2(textField: UITextField)
      {
          var toolbar1:UIToolbar = UIToolbar(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, 40))
          var done:UIBarButtonItem = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Plain, target:self, action: Selector("cancelBtnClicked1:"))
          done.tag  = 203
          var cancel:UIBarButtonItem = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("cancelBtnClicked1:"))
  
          cancel.tag = 202
  
  
     var space:UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
      toolbar1.items = [cancel,space,done]
      toolbar1.barTintColor = UIColor(red: 23.0/255.0, green: 174.0/255.0, blue: 202.0/255.0, alpha: 1)
      toolbar1.tintColor = UIColor.whiteColor()
      txt_Dob.inputAccessoryView = toolbar1
      txt_birthTime.inputAccessoryView = toolbar1
  
      datePicker = UIDatePicker(frame: CGRectMake(toolbar1.frame.size.width - 65, 0, 0, 300))
      let currentCalendar = NSCalendar.currentCalendar()
  
      let dateComponents = NSDateComponents()
      dateComponents.year = -80
      datePicker.maximumDate = NSDate()
  
  
      if txt_Dob.isFirstResponder()
      {
          datePicker.datePickerMode = UIDatePickerMode.Date
      }
      if txt_birthTime.isFirstResponder()
      {
          datePicker.datePickerMode = UIDatePickerMode.Time
          println("selectedDate: \(selectedDate)")
          if selectedDate == NSDate(){
              datePicker.maximumDate = NSDate(timeIntervalSinceNow:0)
          }
      }
  
      datePicker.timeZone = NSTimeZone.localTimeZone()
      datePicker.locale = NSLocale.currentLocale()
      datePicker.calendar = NSCalendar.currentCalendar()
      datePicker.backgroundColor = UIColor.whiteColor()
      txt_Dob.inputView = datePicker
      txt_birthTime.inputView = datePicker
  }
  
  func cancelBtnClicked1(sender:UIButton!)
  {
      var btnTag = sender.tag
  
      if btnTag == 203
      {
          if( txt_Dob.isFirstResponder())
          {
              if sender.tag == 203
              {
                  var dateFormatter = NSDateFormatter()
                  dateFormatter.dateFormat = "dd-MM-yyyy"
                  txt_Dob.text = dateFormatter.stringFromDate(datePicker.date)
  
              }
          }
          else if( txt_birthTime.isFirstResponder())
          {
              if sender.tag == 203
              {
                  var dateFormatter = NSDateFormatter()
                  dateFormatter.dateFormat = "HH:mm"
                  txt_birthTime.text = dateFormatter.stringFromDate(datePicker.date)
                 }
          }
          txt_Dob.resignFirstResponder()
          txt_birthTime.resignFirstResponder()
      }
      else
      {
          self.view.endEditing(true)
      }
  }
  </code></pre>
  
  <p>now I want that If I am selecting today's datepicker should allow me to take time till now, but if I will select date the day before yesterday, it should allow me to take any time.</p>
  
  <p>I am not getting how to do that. Can anyone suggest me how to do that?</p>
  
  <p>Thanks..</p>