Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Adding a time variable to be displayed in the data file?

edited March 2016 in OpenSesame

I would like to add a time variable or time stamp that corresponds to the computer's time in the data file that is
produced when running an experiment. My research team and I want to sync the time on a camera with the time on the computer, so that if something goes wrong we can accurately eliminate data from a specific time in the running experiment. Basically, I want to record the actual time certain things happen when running a file. Can I add a time variable/ stamp in the data file that won't interfere with the actual background and participant's response time of the experiment. I would appreciate any help on how I can actually implement this in my experiment. Thank You.


  • edited 10:11AM

    Hi Diane,

    If the timing precision does not require subsecond timestamps you could use the datetime module. In order to do so, place an inline_script on every position in your experiment tree where you want to check the time.

    In the run phase of the script write:

    import datetime
    # Create a variable for your timestamp
    var.timeA = datetime.time()

    And in your logger item manually add the created variable to write the time along with the rest of the data.

    The timestamp looks like 03/27/16 16:06:15 but you can alter the format by using datetime.strftime(). For more info check:

    I hope this helps!


  • edited 10:11AM

    Hi Laurent,

    Thank you so much for replying and giving me some help. I implemented your idea and I was able to get the timeA variable to show up on my data file. However, it doesn't seem to be recording the actual date or time. In the data it shows 0:00 for all the times variable timeA is logged. Is there any other settings I need to change? Can you help me figure out why it won't actually record a date and time?


  • edited 10:11AM

    Hi Diane,

    My apologies, i should've checked it before responding. Instead of the local time, i think it measured the time between to points, which is 0:00 if there is only one timestamp.

    As an alternative you can use this:

    # Import the time module
    import time
    # Create formatted timestamp, include "%d %b %y" 
    # before the time notation if you want the full date
    var.timeA = time.strftime("%H:%M:%S", time.localtime())

    The logger should include the variable automatically, if not, manually add it.

    Let me know if it works!

Sign In or Register to comment.