转换mysql查询的时间戳和日期
使用数据库时,为了统计信息,必须在指定的日期查询记录,但数据库中存储了很多时间戳
虽然有时会直接保存日期,但查询时可能不那么顺利。
mysql有两个函数:
from_UNIXtime(time_stamp ) -将时间戳转换为日期
UNIX_timestamp(date ) -将指定的日期或日期字符串转换为时间戳
例如:from_UNIXtime(time_stamp )那样
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[平面]
slectfrom_UNIXtime(1382544000;
-------------请参阅
|from_UNIXtime(1382544000 ) |
-------------请参阅
| 2013-10-24 00:00:00 |
-------------请参阅
例如:UNIX_timestamp(date )那样
[平面]
选择UNIX _ timestamp (date (2013-10-24 ) );
-------------请参阅
| UNIX _ timestamp (date (2013-10-24 ) ) |
-------------请参阅
| 1382544000 |
-------------请参阅
查询当天订单的记录:时
[平面]
选择计数(* ) fromb_orderwheredate_format ) from_UNIXtime ) create_time、' %Y-%m-%d ' )=date_forme
这样也可以是:
[平面]
selectcount(* ) fromb _ orderwherecreate _ time=UNIX _ timestamp (2013-10-240033600:00 ) ) andcreate_timestamp 013-240000336000 ) )
取消
评论