How do I use the Date Picker View on mobile?
This lesson describes how to use mobilePickDate to set a date, a time or both a date and time. Screen captures and source code are provided.
Introduction
The command mobilePickDate provides a native date picker interface that allows users to set the date, the time or the date and time, depending on the parameters passed to mobilePickDate. The parameters to this command allow the selection mode, selection range, a current value and the minute interval to be specified.
Parameters are specified in seconds since the UNIX Epoch, except for the minute interval, that is specified in minutes. The selected date and time is returned in the result variable.
Getting the Date

You can launch the date picker to select a date only with the following code:
on mouseUp pButtonNumber
local tDateResult
// launch the date picker
mobilePickDate "date"
// get the result
put the result into tDateResult
// check and display the result in the text field
if tDateResult is 0 then
put "No Selection Made" into field "DateField"
else
convert tDateResult from seconds to abbreviated date
put tDateResult into field "DateField"
end if
end mouseUp
This code does not provide any restrictions on the date range from which a selection can be made or provide a default date value. This means that the default date is set to the date at which the date picker is launched. The screen capture shows the pick representation for date selection and the result returned to field "DateField", once the date picker is dismissed.
Getting the Time

You can launch the time picker with the following code:
on mouseUp pButtonNumber
local tDateResult
// launch the time picker
mobilePickDate "time",,,,10
// get the result
put the result into tDateResult
// check and display the result in the text field
if tDateResult is 0 then
put "No Selection Made" into field "DateField"
else
convert tDateResult from seconds to short time
put tDateResult into field "DateField"
end if
end mouseUp
This code specifies a minute interval of ten minutes, providing a minute picker wheel with the values 00, 10, ..., 40, 50. Other settings are not provided. This means that the default time is set to the time at which the time picker is launched. The screen capture shows the pick representation for time selection and the result returned to field "DateField", once the time picker is dismissed.
Getting the Date and Time (iOS Only)

You can launch the date and time picker by using the following code:
on mouseUp pButtonNumber
local tSelected, tRangeStart, tRangeEnd, tInterval, tDateResult
put "02/11/2018" into tSelected // the date and time selected by default
put "01/01/2018" into tRangeStart // the minimum date and time that can be selected
put "05/06/2018" into tRangeEnd // the maximum date and time that can be selected
put 5 into tInterval
// convert the dates into seconds since the UNIX Epoch
convert tSelected to seconds
convert tRangeStart to seconds
convert tRangeEnd to seconds
// launch the date and time picker
mobilePickDate "dateTime", tSelected, tRangeStart, tRangeEnd, tInterval
// get the result
put the result into tDateResult
// check and display the result in the text field
if tDateResult is 0 then
put "No Selection Made" into field "DateField"
else
convert tDateResult from seconds to internet date
put tDateResult into field "DateField"
end if
end mouseUp
This code restricts the date range to a value between 20 July 2011 and 8 August 2011 from which a selection can be made. The default date is set to 29 July 2011. The screen capture shows the pick representation for date selection and the result returned to field "DateField", once the date picker is dismissed.
Note: The dateTime option is only available on iOS.
Hello,
I reproduced the example above putting the provided code in a button, but I'm getting the following error:
1. if I use the command as described in the Dictionary i get the error
button "Button-getDate": execution error at line 5 (Handler: can't find handler) near "mobilePickDate", char 1
2. if I use the code example I get the error
button "Button-getDate": execution error at line 5 (Handler: can't find handler) near "iphonePickDate", char 1
I'm using Live Code 5.5.1 for Android. Am I missing a addon or plugin ?
Thanks,
Paulo