zoukankan      html  css  js  c++  java
  • MySQL 当前时间,今日时间,前日时间 详解

    MySQL 获取当前日期及日期格式

    获取系统日期: NOW()

    格式化日期: DATE_FORMAT(date, format)

    注: date:时间字段

    format:日期格式

    返回系统日期,输出 2009-12-25 14:38:59

    格式化 当前日期

    mysql> select date_format(now(),'%y-%m-%d');
     
    +-----------+
    | 20-12-0 |
    +-----------+
     

    MySQL 获得当前日期时间 函数

    1 获得当前日期+时间(date + time)函数:now()    年月日时分秒都显示

    mysql> select now();

    +---------------------+
    | now() |
    +---------------------+
    | 2020-12-02 14:55:44 |
    +---------------------+
     

    2. 获得当前日期(date)函数:curdate()  只显示当前 年月日

    mysql> select curdate();

    +------------+
    | curdate() |
    +------------+
    | 2020-12-02|
    +------------+
     
     
    我看到网上好多帖子 写的都是 固定一天或者 范围选择一天  如果加到查询中就不起作用了 
    如果想要查询 从昨天往前的  可以这样写 
     
    1  :select * from 表名 where 字段 < (select curdate())           看情况 加排序  
     
    只查询昨天 
     
    2  :SELECT count(*) FROM 表名  WHERE TO_DAYS(NOW()) - TO_DAYS(字段) = 1
     
     
     
    3. 获得当前时间(time)函数:curtime()   只显示当前 时分秒
     
    mysql> select curtime(); 
    +-----------+
    | curtime() |
    +-----------+
    | 14:55:58 |
    +-----------+
     
     

    4. 获得当前 UTC 日期时间函数:utc_date(), utc_time(), utc_timestamp()

    mysql> select utc_timestamp(), utc_date(), utc_time(), now()

    +---------------------+------------+------------+---------------------+
    | utc_timestamp() | utc_date() | utc_time() | now() |
    +---------------------+------------+------------+---------------------+
    | 2008-08-08 14:47:11 | 2008-08-08 | 14:47:11 | 2008-08-08 22:47:11 |
    +---------------------+------------+------------+---------------------+
     
  • 相关阅读:
    Struts框架之结果页面的跳转
    eclipse中运行tomcat提示端口被占的4种解决方案
    在Struts2框架中使用Servlet的API
    Struts2框架之Action类的访问
    判断有无网
    UITextField银行卡加空格
    关于UI_USER_INTERFACE_IDIOM() & UIDevice.model
    OC导航栏跳转指定界面
    oc UIAlertController封装
    升级到macSierra 10.12之后 在模拟器上面滑动视图很卡,
  • 原文地址:https://www.cnblogs.com/wy919/p/14073723.html
Copyright © 2011-2022 走看看