Question

I need to sort some queries based on day, hour, week, month etc.

Currently the query look like this:

$this->data['fooshs'] = DB::table('fooshs')->where('id', '=', $id)->first();

Now I would only want the the fooshs from last month, I have a created_at for this.

Since my lacking skills of Query Builder, it would look like:

SELECT COUNT(id) AS `fooshs` FROM `fooshs` WHERE `id´ = ? AND `created_at` > DATE_SUB(NOW(), INTERVAL 1 DAY)

How can I write the sql query above in Query Builder?

The DATE_SUB ... part.

No correct solution

OTHER TIPS

Something like this:

DB::table('fooshs')
      ->where('id', '=', $id)
      ->where('created_at', '>', new Illuminate\Database\Query\Expression('DATE_SUB(NOW(), INTERVAL 1 DAY)'))
      ->first()
;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top