Hi guys i have a from where user is going to select a course from drop down and second input user will select expired date that should be optional.so when user didn't give date it is showing error as `Your Due date should be in future.`

I don't know why it is showing like that if i didn't give any date in input field also.

here is my code:

```
if (isset($_POST['assigncourse'])) {

    $courseid = $_POST['courseid'];
    //$duedate = date('Y-m-d', strtotime($_POST['duedate']));
    $duedate = strtotime($_POST['duedate']);
    $now = strtotime(date('Y-m-d'));
    if ($now < $duedate) 
    {
        $courseid = required_param('courseid', PARAM_TEXT);
        $groupid = required_param('groupid', PARAM_TEXT);

        $insert_record = new stdClass();
        $insert_record->courseid = $courseid;
        $insert_record->groupid = $_SESSION['groupid'];
        $insert_record->duedate = $duedate;
        $insert_record->createdby= $id;
        $insert_record->createdon = date('Y-m-d H:i:s');
        $sql1 = "SELECT *  
                    FROM mdl_ppc_assigncourses_group 
                    WHERE groupid='".$_SESSION['groupid']."' 
                    AND courseid='$courseid'";
        $courses = $DB->get_records_sql($sql1);
        if (count($courses) > 1) {
            $errorMessage = "The course already taken!";
        } else {
        $DB->insert_record('ppc_assigncourses_group', $insert_record);
        }
    } else {
        $errorMessage = "Your Due date should be in future.";
    }
}

```

Here is my form:

```
<!-- /.card-header -->

<form class="form-horizontal" id="sign-in" style="margin-left: -2px; padding: 15px 15px 0px 15px" method="post" role="form"  data-parsley-validate="" novalidate=""> 
        <input type="hidden" name="groupid" class="col-md-12 form-control" id="inputEmail3"  required="" value="<?php echo $_SESSION['groupid']; ?>" >
        <!-- select -->
         <input type="hidden" name="depid" class="col-md-12 form-control" id="inputEmail3"  required="" value="<?php echo $_SESSION['depid']; ?>" >
        <div class="form-group">
            <label>Choose Course</label>
            <select name="courseid" id="courseid" class="form-control" required>     
                <?php
                $sql = "select id,fullname from {course} where id!='1' ";
                $courses = $DB->get_records_sql($sql);
                ?>

                <option value="">Choose Course</option>
                <?php
                if (sizeof($courses)): foreach ($courses as $row):
                        $coursename = $row->fullname;
                        ?> 
                        <option value="<?php echo $row->id; ?>"><?php echo $row->fullname; ?></option> 
                        <?php
                    endforeach;
                endif;
                ?>        
            </select> 
        </div>
         <div class="form-group label-floating">
            <label class="control-label">Due Date</label>
            <input type="text" class="form-control" id="datepicker" name="duedate" > 
        </div>

      <div class="form-group">
          <button  type="submit" name="assigncourse"  id="submit"  class="btn btn-info form-control">Assign</button>
      </div>
    </form>

```

Can anyone help me what mistake i have done.

Thanks in advance.