Quiz result report date format

Quiz result report date format

by JOSE RAMIREZ -
Number of replies: 5

Hi, all.

Is there a way to configure the dates in the Quiz result report to a more standarized format (YYYY-MM-DD HH:MM)? I haven't been able to find a configuration option. Should I dig into the code instead?

This is the report I'm refering to:


I'm using Moodle 3.10.

Thanks!

Average of ratings: -
In reply to JOSE RAMIREZ

Re: Quiz result report date format

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello Jose,

I am not sure whether or not there is an option to display dates in ISO 8601 format in the Quiz report. Maybe someone else can answer you.

In case this option is not available, you can modify the Moodle PHP code on the server side or add JavaScript on the client side. It is this last solution that I propose here which consists in putting the following code in Site administration / Appearance / Additional HTML / Before BODY is closed:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>
<script>
// Change date to ISO 8601 format in the Quiz report page
if ($("body").is("#page-mod-quiz-report")) {
    $("td.cell.c5").each(function(){
        var isdate = ( $(this).text() != "" ) && ( $(this).text() != "-" );
        if (isdate) {
            var d = new Date($(this).text());
            var time = $(this).text().slice(-8);
            var dstring = d.getFullYear() + '-' + ('0' + (d.getMonth()+1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2) + '  ' + time;
            $(this).text(dstring);
        }
    });
    $("td.cell.c6").each(function(){
        var isdate = ( $(this).text() != "" ) && ( $(this).text() != "-" );
        if (isdate) {
            var d = new Date($(this).text());
            var time = $(this).text().slice(-8);
            var dstring = d.getFullYear() + '-' + ('0' + (d.getMonth()+1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2) + '  ' + time;
            $(this).text(dstring);
        }
    });
}
</script>

You will get something like this:

ForumQuiz_20210412_0141.png

Of course, the 12 hour format could also be changed to the 24 hour format. The above script modifies the format of the dates only on the screen. If you download the table in Excel format, you can easily change the date format using Excel's cell formatting.

Average of ratings: Useful (1)
In reply to Dominique Bauer

Re: Quiz result report date format

by JOSE RAMIREZ -
Wow, nice Javascript trick, Dominique. Thanks for taking the time to respond.
In reply to JOSE RAMIREZ

Re: Quiz result report date format

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Date formatting in Moodle is controlled by which 'Language pack' you have installed. As such, you can control it using Language customisation. The strings that control this are in 'langconfig'.
Average of ratings: Useful (2)
In reply to Tim Hunt

Re: Quiz result report date format

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
Hello Tim,

Of course. I forgot that we could do it with the language packs.

Thank you for stepping into the conversation and giving a more appropriate answer.smile