0

I am trying to show a list reminders with only today's date on and it's only showing anything with today's dte and after today's date.

This is what I have so far;

<?php
include '../../main.php';
check_loggedin($pdo);
$now = date("Y-m-d h:i:sa");
$stmt = $pdo->prepare('SELECT * FROM care_plan_review where reminder_date > ? order by id desc');
$stmt->execute([$now]);
$allReview = $stmt->fetchAll(PDO::FETCH_ASSOC);

// var_dump($now);
// exit();
?>
  • The `a` in `Y-m-d h:i:sa` add a _am_ or _pm_ after the time, I'm not sure MySQL can cope with that? Anyway, MySQL does have its own `NOW()` function, why not use that? If you don't want to do that try: `Y-m-d H:i:s`. What type does column `reminder_date` have? – KIKO Software Nov 26 '21 at 14:51
  • I've removed the A from the code. The column for the reminder date is reminder_date –  Nov 26 '21 at 14:59
  • Please note you have to capitalize the `h` to go from the 12-hour format to the 24-hour format. I was asking for the type of column `reminder_date`. Something like TEXT, VARCHAR or DATETIME. – KIKO Software Nov 26 '21 at 15:02

1 Answers1

1

To show the records only belongs to today you can use following SQL query.

SELECT * FROM care_plan_review where reminder_date = ? order by id desc

Here is the modified code,

<?php

include '../../main.php';
check_loggedin($pdo);
$now = date("Y-m-d"); // Use only date
$stmt = $pdo->prepare('SELECT * FROM care_plan_review where reminder_date = ? order by id desc');
$stmt->execute([$now]);
$allReview = $stmt->fetchAll(PDO::FETCH_ASSOC);

?>
  • 1
    Getting there. I think you also need to use the `DATE(reminder_date)` in the query, to restrict the `reminder_date`, which probably also contains a time, to a date. – KIKO Software Nov 26 '21 at 15:06