Currently, I am doing mySQL queries as such selecting a unix time stamp from a database, like so:
SELECT 开发者_C百科DATE(FROM_UNIXTIME(time)) AS theday, COUNT(id) AS thecount FROM `table`
WHERE `time`>=UNIX_TIMESTAMP(CURRENT_DATE - > INTERVAL 14 DAY)
GROUP BY theday
ORDER by theday DESC
How would I go about doing a similar query but selecting a DATETIME format? Instead of a unix time stamp?
For example,
0000-00-00 00:00:00
I think MySql DATE_FORMAT will work for you.
mysql_query("SELECT DATE_FORMAT(time, '%Y-%m-%d %H:%i:%s') AS theday, COUNT(id) AS thecount FROM table WHERE time>=UNIX_TIMESTAMP(CURRENT_DATE - INTERVAL 14 DAY) GROUP BY theday ORDER by theday DESC");
Update:
Based on your comment, you can use DATE
function to select date portion from your datetime field:
SELECT DATE(time)
How would I go about doing a similar query but selecting a DATETIME format? Instead of a unix time stamp?
Instead of:
SELECT DATE(FROM_UNIXTIME(time))
You can select your datetime field directly:
SELECT time
精彩评论