Last active
March 24, 2016 01:41
-
-
Save adamfairholm/af88caf5bd0e585154ed to your computer and use it in GitHub Desktop.
Laravel's where date functions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Laravel has some date functions in the query builder that I never really | |
// see mentioned. Most of the time when a user needs to do a MONTH(col) select, | |
// they are advised to do something like this: | |
$employees = Employee::where(DB::Raw('MONTH(hired_at)'), '=', 4)->get(); | |
// However, Laravel seems to have query builder functions that take care of this. | |
// The above query could be rewritten as: | |
$employees = Employee::whereMonth('hired_at', '=', 4)->get(); | |
// There are also functions for whereYear(), and whereDay(). | |
// This all resolves to a dateBasedWhere() function in the query grammar | |
// that is defined in the main Grammar and extended for the postgres grammar. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used same as you why It not work
$tran = TillTransaction::where(DB::raw('DATE(open_time)'),'=','2016-03-24')->get();