Home > Database > Mysql Tutorial > MySQL日期计算及格式转换问题_MySQL

MySQL日期计算及格式转换问题_MySQL

WBOY
Release: 2016-06-01 13:48:53
Original
972 people have browsed it

bitsCN.com

做开发的时候经常会碰到以下几个问题

  1. 使用mysql的内置函数将时间轴转成对应的日期

  方法一:使用from_unixtime(unix_timestamp)函数即可实现,

  如:SELECT FROM_UNIXTIME('1339127478');

           结果:2012-06-08 11:51:18

           SELECT FROM_UNIXTIME('1339127478','%Y-%m-%d');

            结果:2012-06-08

  2.使用mysql的内置函数对日期进行计算

  如:选择符合“三个小时之前”的所有订单

  方法一:使用UNIX_TIMESTAMP()将时间转成时间轴,就容易比较了

  SQL语句:

  SELECT * FROM `order` WHERE UNIX_TIMESTAMP(order_time)> (UNIX_TIMESTAMP(NOW())-3600*3)

  方法二:待续

待续......

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template