diff --git a/blocks/myoverview/classes/output/main.php b/blocks/myoverview/classes/output/main.php
index 16473569c4c..492496b2018 100644
--- a/blocks/myoverview/classes/output/main.php
+++ b/blocks/myoverview/classes/output/main.php
@@ -444,6 +444,8 @@ class main implements renderable, templatable {
         $sort = '';
         if ($this->sort == BLOCK_MYOVERVIEW_SORTING_SHORTNAME) {
             $sort = 'shortname';
+        } else if ($this->sort == BLOCK_MYOVERVIEW_SORTING_ENROLTIME) {
+            $sort = 'ue.timemodified DESC';
         } else {
             $sort = $this->sort == BLOCK_MYOVERVIEW_SORTING_TITLE ? 'fullname' : 'ul.timeaccess desc';
         }
diff --git a/blocks/myoverview/lang/en/block_myoverview.php b/blocks/myoverview/lang/en/block_myoverview.php
index 50f9d692c02..517aa1f2704 100644
--- a/blocks/myoverview/lang/en/block_myoverview.php
+++ b/blocks/myoverview/lang/en/block_myoverview.php
@@ -85,6 +85,7 @@ $string['show'] = 'Restore to view';
 $string['sortbytitle'] = 'Sort by course name';
 $string['sortbylastaccessed'] = 'Sort by last accessed';
 $string['sortbyshortname'] = 'Sort by short name';
+$string['sortbyenroltime'] = 'Sort by enrol time';
 $string['privacy:request:preference:set'] = 'The value of the setting \'{$a->name}\' was \'{$a->value}\'';
 
 // Deprecated since Moodle 4.0.
diff --git a/blocks/myoverview/lib.php b/blocks/myoverview/lib.php
index 8352f63ab05..eabbc4fa11f 100644
--- a/blocks/myoverview/lib.php
+++ b/blocks/myoverview/lib.php
@@ -48,6 +48,7 @@ define('BLOCK_MYOVERVIEW_CUSTOMFIELD_EMPTY', -1);
 define('BLOCK_MYOVERVIEW_SORTING_TITLE', 'title');
 define('BLOCK_MYOVERVIEW_SORTING_LASTACCESSED', 'lastaccessed');
 define('BLOCK_MYOVERVIEW_SORTING_SHORTNAME', 'shortname');
+define('BLOCK_MYOVERVIEW_SORTING_ENROLTIME', 'enroltime');
 
 /**
  * Constants for the user preferences view options
@@ -106,7 +107,8 @@ function block_myoverview_user_preferences() {
         'choices' => array(
             BLOCK_MYOVERVIEW_SORTING_TITLE,
             BLOCK_MYOVERVIEW_SORTING_LASTACCESSED,
-            BLOCK_MYOVERVIEW_SORTING_SHORTNAME
+            BLOCK_MYOVERVIEW_SORTING_SHORTNAME,
+            BLOCK_MYOVERVIEW_SORTING_ENROLTIME
         )
     );
     $preferences['block_myoverview_user_view_preference'] = array(
diff --git a/blocks/myoverview/templates/nav-sort-selector.mustache b/blocks/myoverview/templates/nav-sort-selector.mustache
index d79aaf57db2..019ae82763b 100644
--- a/blocks/myoverview/templates/nav-sort-selector.mustache
+++ b/blocks/myoverview/templates/nav-sort-selector.mustache
@@ -33,6 +33,7 @@
                 {{#title}}{{#str}} sortbytitle, block_myoverview {{/str}}{{/title}}
                 {{#lastaccessed}}{{#str}} sortbylastaccessed, block_myoverview {{/str}}{{/lastaccessed}}
                 {{#shortname}}{{#str}} sortbyshortname, block_myoverview {{/str}}{{/shortname}}
+                {{#enroltime}}{{#str}} sortbyenroltime, block_myoverview {{/str}}{{/enroltime}}
             </span>
         </button>
         <ul class="dropdown-menu" role="menu" data-show-active-item data-skip-active-class="true" aria-labelledby="sortingdropdown">
@@ -53,6 +54,11 @@
                     {{#str}} sortbylastaccessed, block_myoverview {{/str}}
                 </a>
             </li>
+            <li>
+                <a class="dropdown-item" href="#" data-filter="sort" data-pref="enroltime" data-value="ue.timemodified desc" aria-controls="courses-view-{{uniqid}}" role="menuitem" {{#enroltime}}aria-current="true"{{/enroltime}}>
+                    {{#str}} sortbyenroltime, block_myoverview {{/str}}
+                </a>
+            </li>
         </ul>
     </div>
 </div>
diff --git a/lib/enrollib.php b/lib/enrollib.php
index 30effb35a1e..f6c1ad7aecc 100644
--- a/lib/enrollib.php
+++ b/lib/enrollib.php
@@ -625,6 +625,7 @@ function enrol_get_my_courses($fields = null, $sort = null, $limit = 0, $coursei
     $orderby = "";
     $sort    = trim($sort);
     $sorttimeaccess = false;
+    $sorttimeenrol = false;
     if (!empty($sort)) {
         $rawsorts = explode(',', $sort);
         $sorts = array();
@@ -656,6 +657,9 @@ function enrol_get_my_courses($fields = null, $sort = null, $limit = 0, $coursei
                     if ($prefix === 'ul') {
                         $sorts[] = "COALESCE({$prefix}.{$fieldname}, 0) {$sortdirection}";
                         $sorttimeaccess = true;
+                    } else if ($prefix === 'ue') {
+                        $sorts[] = "COALESCE({$prefix}.{$fieldname}, 0) {$sortdirection}";
+                        $sorttimeenrol = true;
                     } else {
                         // Check if the field name that matches with the prefix and just append to sorts.
                         $sorts[] = $rawsort;
@@ -671,6 +675,9 @@ function enrol_get_my_courses($fields = null, $sort = null, $limit = 0, $coursei
                         if ($prefix === 'ul') {
                             $sorts[] = "COALESCE({$prefix}.{$sortfield}, 0) {$sortdirection}";
                             $sorttimeaccess = true;
+                        } else if ($prefix === 'ue') {
+                            $sorts[] = "COALESCE({$prefix}.{$sortfield}, 0) {$sortdirection}";
+                            $sorttimeenrol = true;
                         } else {
                             $sorts[] = "{$prefix}.{$sortfield} {$sortdirection}";
                         }
@@ -705,6 +712,8 @@ function enrol_get_my_courses($fields = null, $sort = null, $limit = 0, $coursei
 
     $timeaccessselect = "";
     $timeaccessjoin = "";
+    $timeenrolselect = "";
+    $timeenroljoin = "";
 
     if (!empty($courseids)) {
         list($courseidssql, $courseidsparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
@@ -737,6 +746,12 @@ function enrol_get_my_courses($fields = null, $sort = null, $limit = 0, $coursei
             $timeaccessselect = ', ul.timeaccess as lastaccessed';
             $timeaccessjoin = "LEFT JOIN {user_lastaccess} ul ON (ul.courseid = c.id AND ul.userid = :userid2)";
         }
+
+        if ($sorttimeenrol) {
+            $params['userid2'] = $USER->id;
+            $timeenrolselect = ', ue.timemodified as enroltime';
+            $timeenroljoin = "JOIN {enrol} e ON e.courseid = c.id JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = :userid2)";
+        }
     }
 
     // When including non-enrolled but accessible courses...
@@ -797,10 +812,11 @@ function enrol_get_my_courses($fields = null, $sort = null, $limit = 0, $coursei
 
     // Note: we can not use DISTINCT + text fields due to Oracle and MS limitations, that is why
     // we have the subselect there.
-    $sql = "SELECT $coursefields $ccselect $timeaccessselect
+    $sql = "SELECT $coursefields $ccselect $timeaccessselect $timeenrolselect
               FROM {course} c
               JOIN ($courseidsql) en ON (en.courseid = c.id)
            $timeaccessjoin
+           $timeenroljoin
            $ccjoin
              WHERE $wheres
           $orderby";
