1. DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据。 DATE_FORMAT(date,format) format参数的格式有 %a 缩写星期名 %b 缩写月名 %c 月,数值 %D 带有英文前缀的月中的天 %d 月的天,数值(00-3
1. DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据。
DATE_FORMAT(date,format)
format参数的格式有
例子:
DATE_FORMAT(NOW(),'%b %d %Y %h:%i %p')
DATE_FORMAT(NOW(),'%m-%d-%Y')
DATE_FORMAT(NOW(),'%d %b %y')
DATE_FORMAT(NOW(),'%d %b %Y %T:%f')
输出结果:
Dec 29 2008 11:45 PM
12-29-2008
29 Dec 08
29 Dec 2008 16:25:46
2. MySQL 格式化函数 FROM_UNIXTIME()
SELECT FROM_UNIXTIME(date, '%Y-%c-%d %h:%i:%s' ) as post_date ,
date_format(NOW(), '%Y-%c-%d %h:%i:%s' ) as post_date_gmt
FROM `article` where outkey = 'Y'
1、FROM_UNIXTIME( unix_timestamp )
参数:一般为10位的时间戳,如:1417363200
返回值:有两种,可能是类似 'YYYY-MM-DD HH:MM:SS' 这样的字符串,也有可能是类似于 YYYYMMDDHHMMSS.uuuuuu 这样的数字,具体返回什么取决于该函数被调用的形式。
mysql> select FROM_UNIXTIME(1344887103);
+---------------------------+
| FROM_UNIXTIME(1344887103) |
+---------------------------+
| 2012-08-14 03:45:03 |
+---------------------------+
1 row in set (0.00 sec)
2、FROM_UNIXTIME( unix_timestamp ,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()) 就是我们需要的判断
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一些帮助,如果有疑问大家可以留言交流。