mysql提供了两个函数:

from_unixtime(time_stamp)   ->  将时间戳转换为日期

unix_timestamp(date)             ->  将指定的日期或者日期字符串转换为时间戳

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[plain]
select from_unixtime(1382544000); 
+---------------------------+ 
| from_unixtime(1382544000) | 
+---------------------------+ 
| 2013-10-24 00:00:00       | 
+---------------------------+ 
如: unix_timestamp(date)
  
[plain]
select unix_timestamp(date('2013-10-24')); 
+------------------------------------+ 
| unix_timestamp(date('2013-10-24')) | 
+------------------------------------+ 
|                         1382544000 | 
+------------------------------------+ 
  
如果要查询当天的订单的记录:
[plain]
select count(*) from b_order Where  date_format(from_unixtime(create_time),'%Y-%m-%d') = date_format(now(),'%Y-%m-%d'
  
也可以这样:
[plain]
select count(*) from b_order Where  create_time >= unix_timestamp('2013-10-24 00:00:00') and create_time <=  unix_timestamp('2013-10-24 23:59:59') ; 

mysql 日期转换sql函数的更多相关文章

  1. 随记MySQL的时间差函数(TIMESTAMPDIFF、DATEDIFF)、日期转换计算函数(date_add、day、date_format、str_to_date)

    时间差函数(TIMESTAMPDIFF.DATEDIFF) 需要用MySQL计算时间差,使用TIMESTAMPDIFF.DATEDIFF,记录一下实验结果 select datediff(now(), ...

  2. Mysql日期转换函数、时间转换函数

    Mysql日期转换函数.时间转换函数 一.MySQL 获得当前日期时间 函数 1,获得当前日期+时间(date + time)函数:now(): select now(); 结果: :: 2,获得当前 ...

  3. MySQL日期函数与日期转换格式化函数大全

    Mysql作为一款开元的免费关系型数据库,用户基础非常庞大,本文列出了MYSQL常用日期函数与日期转换格式化函数 1.DAYOFWEEK(date) 1 2 SELECT DAYOFWEEK('201 ...

  4. MySql日期与时间函数

    select DATE_FORMAT(date_sub(current_date(), interval 1 day), '%Y-%m-%d') -- 2018-05-29(昨天) select DA ...

  5. 转)MySQL日期与时间函数

    -- MySQL日期时间处理函数 -- 当前日期:2017-05-12(突然发现今天512,是不是会拉防空警报) SELECT NOW() FROM DUAL;-- 当前日期时间:2017-05-12 ...

  6. MySQL日期时间处理函数

    -- MySQL日期时间处理函数SELECT NOW() FROM DUAL;-- 当前日期时间:2017-05-12 11:41:47-- 在MySQL里也存在和Oracle里类似的dual虚拟表: ...

  7. Mysql日期时间Extract函数介绍

    MySQL日期时间Extract函数的优点在于可以选取日期时间的各个部分,从年一直到微秒,让我们对MySQL日期时间的处理更为轻松. MySQL 日期时间 Extract(选取)函数.1. 选取日期时 ...

  8. mysql日期相关的函数

    1.获取当前时间: /** 获得当前日期+时间(date + time)函数:now(), 常用 **/ select now() from dual; /** 获取当前时间戳,current_tim ...

  9. MySQL日期和时间函数汇总

    本文基于MySQL8.0 本文介绍MySQL关于日期和时间操作的函数. 日期和时间函数 函数 描述 ADDDATE() 给日期值添加时间值 ADDTIME() 添加time CONVERT_TZ() ...

随机推荐

  1. Storm的基本概念

    Storm的基本概念 Topology:拓扑,也俗称一个任务,类似于MapReduce中的job.将Spout.Bolt整合起来的拓扑图.定义了Spout和Bolt的结合关系.并发数量.配置等等. S ...

  2. Git提交代码的小知识

    1.需要切换到项目目录下并创建一个Repository用于提交代码到这个仓库里 cd /g/....//cd后面有空格,用于进入某个项目文件夹 git init//用于创建Repository 2.添 ...

  3. 小知识 Sql 格式化工具 AutoPostBack后的定位 Post和Get区别 防止被 Fream

    T-Sql 格式化工具 http://jinzb.name/Common/SqlFormat.html AutoPostBack后的定位问题: 给Page 增加属性,MaintainScrollPos ...

  4. LaTeX pdf转eps格式

    使用GSview对pdf 进行 eps 转换 1.准备好PDF文件 例如:f1.pdf 2.打开GSview,转换f1.pdf成为f1.ps 打开GSview,File-->Convert--& ...

  5. exits 和no exits

    exists : 强调的是是否返回结果集,不要求知道返回什么, 比如:  select name from student where sex = 'm' and mark exists(select ...

  6. 87. Scramble String (Java)

    Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...

  7. UITableViewCell背景色.选中背景色,分割线,字体颜色设置

    1.系统默认的颜色设置 //无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色 cell.selectionStyle = ...

  8. redis集群启动和关闭脚本

    创建startall.sh /usr/local/redis/bin/redis-server /usr/local/redis/redis-cluster/7001/redis.conf /usr/ ...

  9. pyquery:轻松、灵活的处理html

    介绍 pyquery是一个专门用来解析html的库,从名字很容易想到jQuery,没错,这完全是仿照jQuery的语法实现的.如果用过jQuery,那么pyquery也很容易上手 初始化html py ...

  10. 记一次部署PHP遇到的编码问题故障

    php开发给我项目和数据库,我按正常部署流程部署,开始发现之梦的后台登陆不了,后发现是属主属组不对,代码直接解压后是root的,更改后,后台能登陆,但部分显示乱码.后将正常的数据库文件重新导入后,显示 ...