Strange datetime error

Today I came across a strange error. I was using datetime to print the code execution nicely (in minutes and seoonds).

→ finish
finish =

1x1 datetime
2024-06-30 21:04:53

→ start
start =

1x1 datetime
2024-06-30 21:01:47

→ duration=finish-start
at line 2 of function %duration_e ( C:\Program Files\scilab-2024.0.0\modules\time\macros%duration_e.sci line 13 )
at line 7 of function %datetime_s_datetime ( C:\Program Files\scilab-2024.0.0\modules\time\macros%datetime_s_datetime.sci line 18 )

Invalid index.

I wonder why I could not calculate the duration.
Anyway, for now I revert to using tic-toc.

finish = toc();
duration = round(finish/6)/10;
disp(duration);

So I get the execution time in minutes, with one decimal instead of seconds.

With kind regards,
Claus

Hello Claus,

you have an “Invalid error” message because you are using duration as variable. duration is a Scilab function and when you assign the result to the duration variable, you overwrite the function.

In Scilab 2024.1.0, I have these results

--> finish = datetime(2024,6,30,21,4,53)

 finish = [datetime]

   2024-06-30 21:04:53

--> start = datetime(2024,6,30,21,1,47)

 start = [datetime]

   2024-06-30 21:01:47

--> d = finish - start

 d = [duration]

   00:03:06

Ah, stupid me

… and now the error message from Scilab makes sense. Thank you for explaining this.

With kind regards,
Claus