In my database I have a date column (type = date). On of the values is this column is '2022-04-29'. When I try to get this date I get an error "Uncaught Error: Call to a member function format() on string".
The code I use:
if ($vrijedag_result = mysqli_query($conn, "SELECT * FROM vrijedagen WHERE datum BETWEEN '$VrijeDagenDatum1' AND '$VrijeDagenDatum2'")) {
if (mysqli_num_rows($vrijedag_result) > 0) {
$vrijedagArray = array();
while ($vrijedagenRij = mysqli_fetch_array($vrijedag_result)) {
$vrijedagdatum = $vrijedagenRij['datum'] -> format('Y-m-d');
array_push($vrijedagArray, "" . $vrijedagdatum . "");
}
}
else {
$vrijedagArray = "";
}
mysqli_free_result($vrijedag_result);
}
In my database the columntype is 'date' and the value I see in PHPMyAdming is 2022-04-29. This value is written to my DB via another php script.
When I try to see the value I receive from my script (using JavaScript Alert) I get '1989'...which is a total of 2022 minus 4 minus 29...
Can somone explane what I'm doing wrong? Does someone have a solution? Thanks in advance!
Edit 1: The error comes on the line '$vrijedagdatum = $vrijedagenRij['datum'] -> format('Y-m-d');'