- datestr(now) returns a character vector and datetime('now') returns a datetime obj.
- datestr(double_scalar) returns a character vector and datetime(double_scalar) throws an error.
How can I programmatically change all my matlab code to use "datetime" rather than "datestr(now)" ?
2 views (last 30 days)
per isakson on 30 Sep 2022
Edited: per isakson on 1 Oct 2022
By mistake, I answer the general question: "Can I do this [replace datestr by datetime] programatically?".
IMHO: It cannot be done "quickly and easily". In the documentation of datestr the syntax section takes seven lines. All cases need to be taken care of. Interpret "Not recommended" as a recommedation to use datetime in new code.
The code below illustrates two problems
double_scalar = datenum(now);
More Answers (1)
Image Analyst on 30 Sep 2022
You can use control-shift-f and search for datestr(now).
Unfortunately that multi-file search capability does not (yet) have a replace capability. So for each line of code found, double click on it in the list of hits to bring up that file in the editor.
Now type control H and tell it to replace datestr(now) with char(datetime).
They're the same. Viz: