sql mysql date conversion function

mysql provides two functions:

 

          from_unixtime (time_stamp) -> is converted to the date stamp

 

          unix_timestamp (date) -> date or specified date string to a timestamp

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' ) ; 

Guess you like

Origin www.cnblogs.com/gyrgyr/p/11240126.html