Medoo SQL database select rows matching a date range

4k views Asked by At

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')

3

There are 3 answers

0
feelsickened On BEST ANSWER

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
));
3
Angolao On

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"))
));
1
Deror On
 $database->select("system_logs", array(
    "date",
    "category",
    "description",
    "class"
), array(
    "date[>]" => strtotime("-7 days")
));