Time comparison use
where
Method
where
Methods support time comparisons, such as:
Greater than a certain time where (' Create_time ', ' > Time ', ' 2016-1-1 ');//less than a certain time where (' create_time ', ' <= ', ' 2016-1-1 '); Time interval queries where (' create_time ', ' Between time ', [' 2015-1-1 ', ' 2016-1-1 ']);
The third parameter can pass in any valid time expression, automatically identifying your time field type, supported time types include timestamps
, datetime
,, date
and int
.
Use
whereTime
Method
whereTime
Method provides a quick query for date and Time fields, as shown in the following example:
Greater than some time db (' user ') ->wheretime (' Birthday ', ' >= ', ' 1970-10-1 ') ->select ();//less than a certain time db (' user ') ->wheretime (' Birthday ', ' < ', ' 2000-10-1 ') ->select ();//time interval query db (' user ') ->wheretime (' Birthday ', ' between ', [' 1970-10-1 ', ' 2000-10-1 ']) ->select ();//Not in a time interval db (' user ') ->wheretime (' Birthday ', ' not between ', [' 1970-10-1 ', ' 2000-10-1 ']) ->select ();
Time-expression
It also provides a more convenient time-expression query, such as:
Get today's Blog db (' blog ') ->wheretime (' create_time ', ' Today ') ->select ();//Get Yesterday's Blog db (' blog '), Wheretime (' Create_time ', ' Yesterday ') ->select ();//Get this week's blog db (' blog ') ->wheretime (' Create_time ', ' Week ') ->select (); Get last week's blog of db (' blog ') ->wheretime (' create_time ', ' previous week ') ->select (); Get this month's blog for db (' blog ') ->wheretime (' Create_time ', ' month ') ->select (); Get last month's blog of db (' blog ') ->wheretime (' create_time ', ' The last month ') ->select (); Get this year's blog db (' blog ') ->wheretime (' create_time ', ' Years ') ->select (); Get last year's blog of DB (' blog ')->wheretime (' Create_time ') (' ' Last year ') ->select ();
If you query the day, this week, this month, and this year, you can also simplify the following:
Get today's Blog db (' blog ') ->wheretime (' Create_time ', ' d ') ->select ();//Get this week's blog db (' blog '), Wheretime (' Create_time ', ' W ') ->select (); Get this month's blog for db (' blog ') ->wheretime (' Create_time ', ' m ') ->select (); Get this year's blog db (' blog ') ->wheretime (' create_time ', ' y ') ->select ();
THINKPHP5 's powerful time query function