# Strange datetime error

**URL:** <https://scilab.discourse.group/t/strange-datetime-error/578>\
**Category:** General usage\
**Created:** [June 30, 2024, 7:29pm UTC](https://scilab.discourse.group/t/strange-datetime-error/578 "2024-06-30T19:29:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cfuttrup](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@cfuttrup](https://scilab.discourse.group/u/cfuttrup)\
**Post date:** [June 30, 2024, 7:29pm UTC](https://scilab.discourse.group/t/strange-datetime-error/578/1 "2024-06-30T19:29:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adeline.carnis](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@adeline.carnis](https://scilab.discourse.group/u/adeline.carnis)\
**Post date:** [July 1, 2024, 12:39pm UTC](https://scilab.discourse.group/t/strange-datetime-error/578/2 "2024-07-01T12:39:36Z")

</div>

Hello Claus,

you have an “Invalid error” message because you are using `duration` as variable. [`duration`](https://help.scilab.org/duration.html) 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

```auto
--> 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

```

---

<div class="post-metadata">

**Author:** ![cfuttrup](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@cfuttrup](https://scilab.discourse.group/u/cfuttrup)\
**Post date:** [July 2, 2024, 5:18pm UTC](https://scilab.discourse.group/t/strange-datetime-error/578/3 "2024-07-02T17:18:31Z")

</div>

Ah, stupid me

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

With kind regards,  
Claus
