generate_date_from_uicalendar

by

 

A simple code example, for generating date output as char from UICalendar.

generate_date_from_uicalendar
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Generate date output from uicalendar 
% Author: Peter Lindberg
% 091210
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function generate_date_from_uicalendar
    close all
    scrsz = get(0,'ScreenSize');
    f = figure('Name', 'Generate Date','Position',[500 scrsz(4)/2 500 200]);

    dateTextHandle = uicontrol(f, 'Style', 'Text', ...
    'String', 'Date:', ...
    'Horizontalalignment', 'left', ...
    'Position', [100 100 50 20]);
    
    dateEditBoxHandle = uicontrol(f, 'Style', 'Edit', ...  
    'Position', [140 100 100 20], ...  
    'BackgroundColor', 'w');

    % Create a push button that startups the UICalendar.

    calendarButtonHandle = uicontrol(f, 'Style', 'PushButton', ...  
    'String', 'Select a single date', ...  
    'Position', [275 100 100 20], ...  
    'callback', @pushbutton_cb);

    runButtonHandle = uicontrol(f, 'Style', 'PushButton', ...  
    'String', 'RUN!!', ...  
    'Position', [205 40 100 20], ...  
    'callback', @pushbuttonrun_cb);

    % To startup UICalendar, create a nested function (callback function) for the push button.

function pushbutton_cb(hcbo, eventStruct)  

% Create a UICALENDAR with the following properties:  
% 1) Highlight weekend dates.  
% 2) Only allow a single date to be selected at a time.  
% 3) Send the selected date to the edit box uicontrol.  
uicalendar('Weekend', [1 0 0 0 0 0 1], ...  
'SelectionType', 1, ...  
'DestinationUI', dateEditBoxHandle,'OutputDateFormat','yyyymmdd');


end

function pushbuttonrun_cb(hcbo, eventStruct)  
    
    enddate = get(dateEditBoxHandle,'string');
   
    if isempty(enddate)
        msgbox('Pick a date!!')
        pause(3)
        return
    else

        %here you can do something with your date ie as input in another
        %program
    end
    close all
    
    msgbox('Finished')
    
    pause(2)
    close all
    


end  
end

Contact us