0

Is it possible to include strtotime date comparison parameters when using medoo to SELECT rows from a database?

I'm using medoo to make database work nice & simple - it's great. However, I'm not sure if I can (but suspect I can) include a date range like parameter when getting rows from my database.

Instead of going through all rows in a foreach routine of what is a large database, I was hoping I could optimise my SELECT/WHERE calls. My loose example/idea is here, but I'm not sure what will work.

$thelogs = $database->select("system_logs", 
    array("date", "category", "description","class"),
    array("date" => .........strtotime('-7 day'))
);

...More information pertaining the way dates are being saved.
Date column is set to datetime in MySQL
Example entry would be: 2014-12-21 05:31:22
In php i'm just using date('Y-m-d H:i:s')

Alessandro Lai
  • 2,254
  • 2
  • 24
  • 32
feelsickened
  • 57
  • 2
  • 10

3 Answers3

1

I managed to get this to work with the following:

    $log_date_range = date("Y-m-d H:i:s", strtotime("-7 days"));

                        $thelogs = $database->select("logs", array(
                        "date",
                        "category",
                        "description",
                        "class",
                        "ID"), array(
    "date[>]" => $log_date_range
));
feelsickened
  • 57
  • 2
  • 10
0

Medoo is supported datetime condition. You can use it like this:

$database->select("system_logs", array(
    "date",
    "category",
    "description",
    "class"
), array(
    "date" => date('Y-m-d H:i:s', strtotime("-7 days"))
));
Angolao
  • 986
  • 1
  • 15
  • 27
  • This isn't returning anything from my database. Should this return only rows with dates specifically 7 days difference - or all rows where the dates are > 7 days ? – feelsickened Dec 24 '14 at 14:57
  • @feelsickened Check your datetime format in database row. The `xxx` in `date('xxx')` should match the format while you inserting the datetime data into database. – Angolao Dec 24 '14 at 18:11
  • Sorry, the above doesn't work. Have updated original question with more information about the datetime format if that helps clarify or reveal the issue. – feelsickened Jan 10 '15 at 19:08
0
 $database->select("system_logs", array(
    "date",
    "category",
    "description",
    "class"
), array(
    "date[>]" => strtotime("-7 days")
));
Deror
  • 51
  • 3
  • This solution appears to return all rows no matter the date. Have updated the original question with saved datetime format info for clarification. – feelsickened Jan 10 '15 at 19:13