How can I change the visible limits of uidatepicker?

4 views (last 30 days)
When using the datepicker component in AppDesigner I want to set the limits which each component presents to the user. In particular I want to be able to choose the year from a greater range than 40 years, which seems to be the default no matter what limits are set, when creating the datepicker component.
See this example:
function mydateapp
f = uifigure('Position',[340 400 415 300]);
d = uidatepicker(f,'DisplayFormat','MM-dd-yyyy',...
'Position',[130 190 150 22],...
'Value',datetime(2000,1,1),...
'Limits', [datetime([1960, 1, 1]), datetime([2040, 1, 1])],...
'ValueChangedFcn', @datechange);
end
  1 Comment
rmit
rmit on 15 Jan 2019
Support has confirmed this is currently not possible. They might consider adding this functionality in a future release.

Sign in to comment.

Answers (1)

Abhipsa
Abhipsa on 30 Jan 2025
Hi, I get that you want the dropdown to show the years from “1960” to “2040”, but it’s showing a range of only 40 years. I am able to reproduce the issue in MATLAB R2024b and R2018b.
You can use this workaround that I have verified in 2024b and 2018b.
If you select any extreme value (highest or lowest) present in the given selection, then the dropdown gets extended up to next 40 years (depending on the values that has been selected).
The "Limits" parameter functions correctly, preventing selection beyond the specified bounds by crossing out the dates that are out of bound.
You can use "doc uidatepicker” command in your MATLAB command window to access the official documentation for “uidatepicker”.

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!