MATLAB: How to include a variable when trying to display a string

num2strstrings

I created a start time and saved it. I want to include this variable in the end of the string, but what I'm doing is not working. Here is my current code:
startHW1=datetime('now');
save HW1 startHW1
disp(['I started HW1 on ', num2str(startHW1)]);

Best Answer

Use the optional output format
startHW1=datetime('now','Format','dd-MMM-yyyy HH:mm:ss');
disp(['I started HW1 on ' startHW1])
or, just use now
startHW1=now;
disp(['I started HW1 on ' datestr(startHW1)])
(Addendum/Erratum: the need for datestr here sorta' defeats the purpose; my faux pas explained further in comment to Stephen...)