MATLAB: How to lock what date ‘today’ is

datetimetoday

I have a function that repeatedly creates date vectors from different dates to today and merges them. If I run the scrips over midnight what's today changes, which causes some bugs. Is there a way to lock what date is today when starting the script? So that if I write:
a = datetime('today');
5 minutes of code
b = datetimte('today');
if a == b
disp('Not bugged')
end
It will display 'Not bugged' even when the date changes in the middle of the code?

Best Answer

Well, the simplest solution is to not ask for today's date several times. You've already got the date you want. Why can't you use that information? Using your example:
a = datetime('today');
%5 minutes of code
%do not ask for today's date again, keep on using a
The other solution is to fix the bugs in your code so that a change of day does not cause problem. (Should be done anyway).