# Logging start and end time of a trial

**URL:** https://discourse.psychopy.org/t/logging-start-and-end-time-of-a-trial/19763
**Category:** Builder
**Created:** [January 20, 2021, 12:13am UTC](https://discourse.psychopy.org/t/logging-start-and-end-time-of-a-trial/19763 "2021-01-20T00:13:48Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Genevieve\_Allaire-Du](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/genevieve_allaire-du/32/3222_2.png) [@Genevieve\_Allaire-Du](https://discourse.psychopy.org/u/Genevieve_Allaire-Du)
#### Post date: [January 20, 2021, 12:13am UTC](https://discourse.psychopy.org/t/logging-start-and-end-time-of-a-trial/19763/1 "2021-01-20T00:13:49Z")

</div>

Dear PsychoPy forum,

I inserted a “python command” block in my experiment in order to be able to log the start and end time of each trial in the psydat files.

In short, it is coded:  
Begin routine: thisExp.addData(“TrialsStartTime”, globalClock.getTime())  
End routine: thisExp.addData(“TrialsEndTime”, globalClock.getTime())

Unfortunately, it doesn’t seem to work. I attached the experiment file and an example of a psydat file.

Any tip would be greatly appreciated. I have no background in programming.

Genevieve

[run1perimeter.psyexp](https://discourse.psychopy.org/uploads/short-url/jtoeFfVnTHTI7jEgwy4lDxU4oJc.psyexp) (51.9 KB)

[004\_perimeter-run1\_2019\_Aug\_26\_1423.xlsx](https://discourse.psychopy.org/uploads/short-url/8JjF0IjghTcbJ5rykYR89TGeOVE.xlsx) (14.8 KB)

---

<div class="post-metadata">

### Author: ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)
#### Post date: [January 20, 2021, 3:02am UTC](https://discourse.psychopy.org/t/logging-start-and-end-time-of-a-trial/19763/2 "2021-01-20T03:02:52Z")

</div>

> [@Genevieve\_Allaire-Du](#):
>
> Unfortunately, it doesn’t seem to work

Hi, please explain exactly what you mean by this — at the moment, we don’t know what the actual problem is.

---

<div class="post-metadata">

### Author: ![Genevieve\_Allaire-Du](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/genevieve_allaire-du/32/3222_2.png) [@Genevieve\_Allaire-Du](https://discourse.psychopy.org/u/Genevieve_Allaire-Du)
#### Post date: [January 20, 2021, 4:52pm UTC](https://discourse.psychopy.org/t/logging-start-and-end-time-of-a-trial/19763/3 "2021-01-20T16:52:13Z")

</div>

Sorry for the lack of clarity.

Only the accuracy and the response time are logged in the psydat file. The start time and end time of the trials is not logged in. I need this later information for fMRI data analysis, i.e. to know exactly at what time (relative to the start of the experiment) each trial was presented.

Thanks in advance!  
Geneviève

---

<div class="post-metadata">

### Author: ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)
#### Post date: [January 20, 2021, 10:43pm UTC](https://discourse.psychopy.org/t/logging-start-and-end-time-of-a-trial/19763/4 "2021-01-20T22:43:37Z")

</div>

You’re doing everything correctly, just looking in the wrong place for the output. In your experiment settings, please switch off “Save Excel file” and “Save csv file (summaries)”. The data file you need for your analysis is obtained from “Save csv file (trial-by-trial)”.

The other two formats do some summarising and so don’t contain all the info you need – I’d actually prefer it if those options were removed, as they only cause issues.

---

<div class="post-metadata">

### Author: ![Genevieve\_Allaire-Du](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/genevieve_allaire-du/32/3222_2.png) [@Genevieve\_Allaire-Du](https://discourse.psychopy.org/u/Genevieve_Allaire-Du)
#### Post date: [January 25, 2021, 8:30pm UTC](https://discourse.psychopy.org/t/logging-start-and-end-time-of-a-trial/19763/5 "2021-01-25T20:30:18Z")

</div>

Dear Michael,

Thank you for your help. It looks like my experiment settings have already been set to “Save csv file (trial-by-trial)” (see screenshot).

Could it be some other experiment setting that I haven’t switched on properly?

Best,  
Genevieve

 ![Screen Shot 2021-01-25 at 12.26.47](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/b/bbdb7c7abd1e427cf0cb9511798909bef07db13f.png)

---

<div class="post-metadata">

### Author: ![Genevieve\_Allaire-Du](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/genevieve_allaire-du/32/3222_2.png) [@Genevieve\_Allaire-Du](https://discourse.psychopy.org/u/Genevieve_Allaire-Du)
#### Post date: [January 25, 2021, 8:37pm UTC](https://discourse.psychopy.org/t/logging-start-and-end-time-of-a-trial/19763/6 "2021-01-25T20:37:11Z")

</div>

Dear Micheal,

Please ignore my last message, indeed when I activate “Save csv file (trial-by-trial)” I get the start time each trial in the csv final.

Many thanks for your help,  
Genevieve
