Mobile DateTime Picker
From Xojo Documentation
The DateTime Picker control is used to let the user choose a date or date-related value. The DateTime Picker can display date values in these formats:
- Time
- Date
- Date and Time
By using a DateTime Picker, you can ensure that you get a valid date value from the user.
Below are common events, properties and methods. Refer to MobileDateTimePicker in the Language Reference for the complete list.
Events
DateChanged - Called when the user selects a date or time). Use the properties below to get the value that was selected.
Properties
SelectedDate - A DateTime value that specified the initial date to have centered in the DateTime Picker. It is also the currently displayed DateTime, so use this to get the date/time value the user has picked. This is applicable when DisplayMode is Date or DateAndTime.
Enabled - A boolean that indicates if the DateTime Picker is enabled and can be used or disabled and cannot be used.
MaximumDate - The maximum date and/or time that can be selected.
MinimumDate - The minimum date and/or time that can be selected.
DisplayMode - Specifies the type of DateTime Picker that is displayed (using the DisplayModes enumeration): TimeOnly, DateOnly, and DateAndTime.
Usage
If you want to get notified every time the DateTime Picker value is changed, then use the DateChanged event handler. If you would prefer to get the value at a time or your own choosing, you can refer to the properties.
For example, if you want to have a button that says "Get Selected Date", then it's Pressed event handler could have code like this:
That same code can also go in the DateChanged event handler, which means it will be called when the date or time changes.
By default the DateTime Picker shows the current date (when in DateOnly or DateAndTime modes). You can also have a different date as the default by setting the SelectedDate property. This code in the Opening event handler for the DateTime Picker sets the default date:
If you are using the TimeOnly mode and want to display a specific time, you would also set it using the SelectedDate property. In this case, be sure to set the time component of the date:
MyDateTimePicker.SelectedDate = halloween
Example Project
- Examples/iOS/Controls/DatePickerExample
See Also
MobileDateTimePicker class