Home  >  Article  >  Backend Development  >  MySQL 日期时间函数常用总结_PHP教程

MySQL 日期时间函数常用总结_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:17:59709browse

 获得当前日期+时间(date + time)1.1    函数:now()

     相关函数:current_timestamp(),localtime(),localtimestamp()

     举例说明:



        2. 获得当前日期(date)

     函数:curdate()

     相关函数:current_date(),current_date

     举例说明:



        3. 获得当前时间(time)

    函数:curtime()

     相关函数:current_time(),current_time

    举例说明


     

        4. MySQL dayof… 

    函数:dayofweek(), dayofmonth(), dayofyear()分别返回日期参数,在一周、一月、一年中的位置。

    举例说明

    set @dt = '2008-08-08';

    select dayofweek(@dt); -- 6

    select dayofmonth(@dt); -- 8

    select dayofyear(@dt); -- 221

    日期‘2008-08-08′ 是一周中的第6 天(1 = Sunday, 2 = Monday, …, 7 = Saturday)

    一月中的第8 天;一年中的第221 天

    www.bkjia.comtruehttp://www.bkjia.com/PHPjc/325580.htmlTechArticle获得当前日期+时间(date+time)1.1函数:now() 相关函数:current_timestamp(),localtime(),localtimestamp() 举例说明: 2.获得当前日期(date) 函数:...
    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn