Time of the query
Time comparison
Use where
method
where
Methods support time comparison, for example:
// more than a certain time WHERE ( 'the create_time', '> Time', '2016-1-1' ); // less than a certain time where ( 'create_time', '< = time', '2016-1-1 ' ); // time interval query where (' create_time ',' between time ', [' 2015-1-1 ',' 2016-1-1 ']);
The third parameter can be passed in any valid time expression, will automatically recognize your time field type, time supported types include timestamps
, datetime
, date
and int
.
Use whereTime
method
whereTime
The method provides a quick and easy reference date and time fields, for example:
// more than a certain time Db :: Table ( 'think_user') -> whereTime ( 'Birthday', '> =', '1970-10-1') -> SELECT (); // less than a certain time Db: : Table ( 'think_user') -> whereTime ( 'Birthday', '<', '2000-10-1') -> SELECT (); // time interval query Db :: table ( 'think_user') -> whereTime ( 'Birthday', 'BETWEEN', [ '1970-10-1', '2000-10-1']) -> SELECT (); // not a certain time interval Db :: table ( 'think_user') - > whereTime ( 'birthday', ' not between', [ '1970-10-1', '2000-10-1']) -> select ();
Time expression
Also it provides a more convenient time query expressions, such as:
// get today's blog Db :: table ( 'think_blog') -> whereTime ( 'create_time', 'Today') -> the SELECT (); // get yesterday's blog Db :: table ( 'think_blog') -> whereTime ( 'create_time', 'Yesterday') -> the SELECT (); // get this week's blog Db :: the Table ( 'think_blog') -> whereTime ( 'create_time', 'week') -> the SELECT (); // get last week's blog Db :: table ( 'think_blog') -> whereTime ( 'create_time', 'Last week') -> the SELECT (); // get this month's blog Db :: table ( 'think_blog' ) -> whereTime ( 'create_time', 'month the') -> the SELECT (); // get blog last month Db ::table('think_blog')->whereTime('create_time', 'last month')->select(); //Get this year's blog Db :: table ( 'think_blog') -> whereTime ( 'create_time', 'year') -> the SELECT (); // get last year's blog Db :: table ( 'think_blog') -> whereTime ( 'create_time', 'last year' ) -> select ();
If the query that day, week, month, year and time, also can be simplified as:
// get today's blog Db :: table ( 'think_blog') - > whereTime ( 'create_time', 'd') -> the SELECT (); // get this week's blog Db :: table ( 'think_blog') - > whereTime ( 'the create_time', 'W') -> SELECT (); // Get month blog Db :: Table ( 'think_blog') -> whereTime ( 'the create_time', 'm') -> SELECT () ; // get this year's blog Db :: table ( 'think_blog') -> whereTime ( 'create_time', 'y') -> select ();
V5.0.5+
Version, you can also use the following method for time inquiry
// query blog within two hours Db :: table ( 'think_blog') -> whereTime ( 'create_time', '- 2 hours') -> select ();