程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> mysql中格式化日期詳解

mysql中格式化日期詳解

編輯:MySQL綜合教程

mysql中格式化日期詳解。本站提示廣大學習愛好者:(mysql中格式化日期詳解)文章只能為提供參考,不一定能成為您想要的結果。以下是mysql中格式化日期詳解正文


1. DATE_FORMAT() 函數用於以不同的格式顯示日期/時間數據。

DATE_FORMAT(date,format) 

format參數的格式有

參數 unix_timestamp :與辦法 FROM_UNIXTIME( unix_timestamp ) 中的參數含義一樣;

參數 format : 轉換之後的時間字符串顯示的格式;

前往值:依照指定的時間格式顯示的字符串;

mysql> select FROM_UNIXTIME(1344887103,'%Y-%M-%D %h:%i:%s'); 
+-----------------------------------------------+ 
| FROM_UNIXTIME(1344887103,'%Y-%M-%D %h:%i:%s') | 
+-----------------------------------------------+ 
| 2012-August-14th 03:45:03      | 
+-----------------------------------------------+ 
1 row in set (0.00 sec) 
mysql> select FROM_UNIXTIME(1344887103,'%Y-%m-%D %h:%i:%s'); 
+-----------------------------------------------+ 
| FROM_UNIXTIME(1344887103,'%Y-%m-%D %h:%i:%s') | 
+-----------------------------------------------+ 
| 2012-08-14th 03:45:03       | 
+-----------------------------------------------+ 
 
1 row in set (0.00 sec) 

3、判別是不是同一天:

SELECT tbl_gamedata.GameMapName,tbl_playerdata.GameMode, tbl_gamedata.MatchMode, tbl_playerdata.GameResult, SUM(tbl_playerdata.GameIsWin) AS tday_winCount, 
   SUM(tbl_playerdata.AssistCount) AS tday_assistCount,SUM(tbl_playerdata.KillCount) AS tday_killCount,
   SUM(tbl_player_title.ThreeKill) AS tday_threeKill,SUM(tbl_player_title.FourKill) AS tday_fourKill,SUM(tbl_player_title.FiveKill) AS tday_fiveKill
 FROM tbl_playerdata 
  LEFT JOIN tbl_gamedata ON tbl_playerdata.GameID = tbl_gamedata.GameID
  LEFT JOIN tbl_player_title ON tbl_player_title.GameID = tbl_playerdata.GameID AND tbl_player_title.PlayerID = tbl_playerdata.PlayerID
 WHERE tbl_playerdata.PlayerID = user_id AND (tbl_playerdata.GameResult = 2 OR tbl_playerdata.GameResult = 3) AND TO_DAYS(FROM_UNIXTIME(tbl_playerdata.GameStartTime)) = TO_DAYS(NOW()) 
 GROUP BY tbl_gamedata.GameMapName, tbl_playerdata.GameMode,tbl_gamedata.MatchMode,tbl_playerdata.GameResult;

其中TO_DAYS(FROM_UNIXTIME(tbl_playerdata.GameStartTime)) = TO_DAYS(NOW()) 就是我們需求的判別

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或許任務能帶來一些協助,假如有疑問大家可以留言交流。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved