MySQL 从时间戳 SQL 中选择日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21151335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:49:52  来源:igfitidea点击:

Select date from timestamp SQL

mysqlsql

提问by Marc Rasmussen

i have the following row in my database:

我的数据库中有以下行:

'1', '1', '1', 'Hello world', 'Hello', '2014-01-14 17:33:34'

Now i wish to select this row and get only the date from this timestamp:

现在我希望选择这一行并仅从该时间戳中获取日期:

i have tried the following:

我尝试了以下方法:

SELECT title,   FROM_UNIXTIME(timestamp,'%Y %D %M') AS MYDATE FROM Team_Note TN WHERE id = 1

I have also tried:

我也试过:

SELECT title,   DATE_FORMAT(FROM_UNIXTIME(`timestamp`), '%e %b %Y') AS MYDATE FROM Team_Note TN WHERE id = 1

However these just return an empty result (or well i get the Hello part but MYDATE is empty)

然而,这些只是返回一个空结果(或者我得到了 Hello 部分但 MYDATE 是空的)

回答by Gordon Linoff

Did you try this?

你试过这个吗?

SELECT title, date(timestamp) AS MYDATE
FROM Team_Note TN
WHERE id = 1

回答by Adarsh Shah

You need to use DATE function for that:

您需要为此使用 DATE 函数:

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date

SELECT title,   
DATE(timestamp) AS MYDATE 
FROM Team_Note TN 
WHERE id = 1