diff --git a/course/modedit.php b/course/modedit.php
index 4b5c615..4f90979 100644
--- a/course/modedit.php
+++ b/course/modedit.php
@@ -304,8 +304,11 @@ if ($mform->is_cancelled()) {
             // The form time is midnight, but because we want it to be
             // inclusive, set it to 23:59:59 on that day.
             if ($cm->availableuntil) {
-                $cm->availableuntil = strtotime('23:59:59',
-                    $cm->availableuntil);
+                $cm->availableuntil = make_timestamp(
+                                                    date('Y', $cm->availableuntil),
+                                                    date('m', $cm->availableuntil),
+                                                    date('d', $cm->availableuntil),
+                                                    '23', '59', '59');
             }
             $cm->showavailability          = $fromform->showavailability;
             condition_info::update_cm_from_form($cm,$fromform,true);
@@ -390,8 +393,11 @@ if ($mform->is_cancelled()) {
             // The form time is midnight, but because we want it to be
             // inclusive, set it to 23:59:59 on that day.
             if ($newcm->availableuntil) {
-                $newcm->availableuntil = strtotime('23:59:59',
-                    $newcm->availableuntil);
+                $newcm->availableuntil = make_timestamp(
+                                                    date('Y', $newcm->availableuntil),
+                                                    date('m', $newcm->availableuntil),
+                                                    date('d', $newcm->availableuntil),
+                                                    '23', '59', '59');
             }
             $newcm->showavailability          = $fromform->showavailability;
         }
