# Time my experiment

**URL:** https://discourse.psychopy.org/t/time-my-experiment/38892
**Category:** Online experiments
**Tags:** timing, pavlovia
**Created:** [February 29, 2024, 6:16pm UTC](https://discourse.psychopy.org/t/time-my-experiment/38892 "2024-02-29T18:16:32Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![sebniko2](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@sebniko2](https://discourse.psychopy.org/u/sebniko2)
#### Post date: [February 29, 2024, 6:16pm UTC](https://discourse.psychopy.org/t/time-my-experiment/38892/1 "2024-02-29T18:16:32Z")

</div>

I want to be able to time my experiment and save that time, from the beginning of the first routine to the beginning of the last routine.

I would need this to work online on pavlovia too.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 29, 2024, 6:21pm UTC](https://discourse.psychopy.org/t/time-my-experiment/38892/2 "2024-02-29T18:21:32Z")

</div>

Begin Experiment

```auto
myClock = core.Clock()

```

Begin Routine (first routine)

```auto
myClock.reset()

```

End Routine (last routine)

```auto
thisExp.addData('Elapsed Time',myClock.getTime())

```

---

<div class="post-metadata">

### Author: ![sebniko2](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@sebniko2](https://discourse.psychopy.org/u/sebniko2)
#### Post date: [February 29, 2024, 8:43pm UTC](https://discourse.psychopy.org/t/time-my-experiment/38892/4 "2024-02-29T20:43:13Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/1/513301f5d2300458f1cd3605737767db46b28a59.png)

Ah it worked offline but I had this pop up when I tried to run the experiment on Pavlovia online.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 29, 2024, 8:58pm UTC](https://discourse.psychopy.org/t/time-my-experiment/38892/5 "2024-02-29T20:58:44Z")

</div>

Sorry – you may have a version which doesn’t translate core.Clock() correctly. You might need to put that one into a Both component and change the JS side to myClock = new util.Clock();

---

<div class="post-metadata">

### Author: ![sebniko2](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@sebniko2](https://discourse.psychopy.org/u/sebniko2)
#### Post date: [February 29, 2024, 11:03pm UTC](https://discourse.psychopy.org/t/time-my-experiment/38892/6 "2024-02-29T23:03:10Z")

</div>

I did that and it worked offline again but didn’t work online in Pavlovia. The actual experiment ran but the “Elapsed Time” did not show up in the datafile.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/8/b80c29ffa90e6b8702661513ab797aa744b69062.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/f/3f071e322349cac71ec478f01dacfaae6b01e1cf.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/f/9f860a2db6a6a84533c0c00f28a938ecaa72cff0.png)

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 29, 2024, 11:28pm UTC](https://discourse.psychopy.org/t/time-my-experiment/38892/7 "2024-02-29T23:28:24Z")

</div>

You have put the code in End Experiment not End Routine of the last routine

---

<div class="post-metadata">

### Author: ![sebniko2](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@sebniko2](https://discourse.psychopy.org/u/sebniko2)
#### Post date: [March 1, 2024, 1:23pm UTC](https://discourse.psychopy.org/t/time-my-experiment/38892/8 "2024-03-01T13:23:14Z")

</div>

Thanks so much, it finally worked.
