Dan Justin
Dan Justin

Reputation: 45

Laravel whereDate() with local timezone

So, basically, I want to build this SQL; notice the "localtime":

select [columns redacted] from "data"
where
  strftime('%Y-%m-%d', "time", "localtime") = cast("2019-05-27" as text)

So far, I've tried:

$data = data::select([columns redacted])
    ->whereDate('time', $date)
    ->get();

And, of course, it generates this:

select [columns redacted] from "data" where strftime('%Y-%m-%d', "time") = cast("2019-05-27" as text)

And I don't know how to pass the "localtime" to whereDate(). Any help would be appreciated.

Upvotes: 1

Views: 369

Answers (1)

user9032546
user9032546

Reputation:

You can use whereRaw

->whereRaw('strftime("%Y-%m-%d", time, "localtime") = ?', ['2019-05-27'])

Upvotes: 1

Related Questions