I’m trying to select the year in MySQL with PHP with this:
session_start();
$school_id = $_SESSION['school_id'];
$section_id = $_POST['section_id'];
$today = date("Y");
$select_grades_deped = "SELECT *
FROM deped_grade_archive
WHERE school_id='$school_id'
AND section_id='$section_id'
AND year(submission_date) ='$today' ";
$query_check_grades= mysql_query($select_grades_deped) or die (mysql_error());
$check_count = mysql_num_rows($query_check_grades);
if($check_count == 0){
$return['checked'] = "0";
}
else{
$return['checked'] = "1";
}
echo json_encode($return);
But unfortunately when I tried the following:
SELECT year( submission_date )
FROM deped_grade_archive
WHERE school_id = '$school_id'
AND section_id = '$section_id'
It returned zero values from my table. I change the data type of submission_date into date data type because it was varchar before but there still no use. Please help guys.
When changing it to the
datedata type, if you don’t set a default value for the column (such asCURRENT_TIMESTAMP), the value will be0000-00-00. Thus, theYEARoperation will return0as shown.You’ll need to update your
submission_datecolumn to the time you wish to specify for each row.