THINKPHP5 's powerful time query function

Source: Internet
Author: User

Time comparison use whereMethod

whereMethods 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 whereTimeMethod

whereTimeMethod 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.