1. Home
  2. Docs
  3. DatePicker by Bitsplash
  4. Using selected dates from script

Using selected dates from script

Start by obtaining a DatePickerSettings object:

var datepicker = GetComponent<DatePickerSettings>();

Enumerating all the selected dates

var selection = datepicker.Content.Selection;
for(int i=0; i<selection.Count; i++)
{
       DateTime t = selection.GetItem(i);
       /// use t in any way you'd like
}

Selecting dates and ranges:

you can use any of the following methods to select dates and ranged programatically:

var selection = datepicker.Content.Selection;

selection.SelectOne(DateTime.Today); // selects the specified date and clears all the rest of the selection
selection.SelectRange(from,to); // selects the specified date range and clears all other dates from the selection
selection.AddDate(DateTime.Today); // adds a new date to the selection.
selection.RemoveDate(DateTime.Today); // removes a date from the selection if it is present

Quering the selection

selection.Contains(DateTime.Today); //returns true if the specified date is contained within the selection
selection.GetItem(0); // returns the first selected date. (this is useful when using singular dates)