zoukankan      html  css  js  c++  java
  • thinkphp5日期时间查询比较和whereTime使用方法

    一、使用where方法进行时间的比较查询

    where(‘create_time’,’> time’,’2019-1-1′); // 大于某个时间
    where(‘create_time’,'<= time’,’2019-1-1′); // 小于某个时间
    where(‘create_time’,’between time’,[‘2018-1-1′,’2019-1-1’]); // 时间区间查询

    二、使用whereTime方法

    whereTime(‘birthday’, ‘>=’, ‘1970-10-1’)->select(); // 大于某个时间
    
    whereTime(‘birthday’, ‘<‘, ‘2000-10-1’)->select(); // 小于某个时间
    
    whereTime(‘birthday’, ‘between’, [‘1970-10-1’, ‘2000-10-1’])->select(); // 时间区间查询
    
    whereTime(‘birthday’, ‘not between’, [‘1970-10-1’, ‘2000-10-1’])->select(); // 不在某个时间区间

    三、时间表达式

    // 获取今天的文章
    Db::table(‘think_news’) ->whereTime(‘create_time’, ‘today’)->select();
    // 获取昨天的文章
    Db::table(‘think_news’)->whereTime(‘create_time’, ‘yesterday’)->select();
    // 获取本周的文章
    Db::table(‘think_news’)->whereTime(‘create_time’, ‘week’)->select();
    // 获取上周的文章
    Db::table(‘think_news’)->whereTime(‘create_time’, ‘last week’)->select();
    // 获取本月的文章
    Db::table(‘think_news’)->whereTime(‘create_time’, ‘month’)->select();
    // 获取上月的文章
    Db::table(‘think_news’)->whereTime(‘create_time’, ‘last month’)->select();
    // 获取今年的文章
    Db::table(‘think_news’)->whereTime(‘create_time’, ‘year’)->select();
    // 获取去年的文章
    Db::table(‘think_news’)->whereTime(‘create_time’, ‘last year’)->select();

    四、如果查询当天、本周、本月和今年的时间,还可以简化为:

    // 获取今天的文章
    Db::table(‘think_news’)->whereTime(‘create_time’, ‘d’)->select();
    // 获取本周的文章
    Db::table(‘think_news’)->whereTime(‘create_time’, ‘w’)->select();
    // 获取本月的文章
    Db::table(‘think_news’)->whereTime(‘create_time’, ‘m’)->select();
    // 获取今年的文章
    Db::table(‘think_news’)->whereTime(‘create_time’, ‘y’) ->select();

    五、时间范围查询

    // 查询两个小时内的文章
    Db::table(‘think_news’)->whereTime(‘create_time’,’-2 hours’)->select();

    转自:http://www.weixuecn.cn/article/14054.html

  • 相关阅读:
    JAVA安装
    capture格式布局
    CSS样式表
    进制的转换
    CentOs7设置主机名称,以及主机名称和ip的对应关系
    CentOS7中NAT网卡设置静态IP
    CentOs7安装配置JDK
    基于Go语言构建区块链:part5
    基于Go语言构建区块链:part4
    BoltDB使用笔记
  • 原文地址:https://www.cnblogs.com/shiliuye/p/15045059.html
Copyright © 2011-2022 走看看