MySQL 仅获取mysql中时间戳中的日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20228731/
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:33:24  来源:igfitidea点击:

Get only the date in timestamp in mysql

mysqldate

提问by sleepsleepsleep90731

On my database under the t_stamp columns I have the date for example

例如,在 t_stamp 列下的数据库中,我有日期

2013-11-26 01:24:34

From that same column I only want to get the date

从同一列我只想得到日期

2013-11-26

How can i do this? Thank You!

我怎样才能做到这一点?谢谢你!

回答by Filipe Silva

You can use date(t_stamp)to get only the date part from a timestamp.

您可以使用date(t_stamp)仅从时间戳中获取日期部分。

You can check the date() function in the docs

您可以在文档中检查 date() 函数

DATE(expr)

Extracts the date part of the date or datetime expression expr.

mysql> SELECT DATE('2003-12-31 01:02:03'); -> '2003-12-31'

日期(expr)

提取日期或日期时间表达式 expr 的日期部分。

mysql> SELECT DATE('2003-12-31 01:02:03'); -> '2003-12-31'

回答by Dilraj Singh

You can convert that time in Unix timestamp by using

您可以使用 Unix 时间戳转换该时间

select UNIX_TIMESTAMP('2013-11-26 01:24:34')

选择 UNIX_TIMESTAMP('2013-11-26 01:24:34')

then convert it in the readable format in whatever format you need

然后将其转换为您需要的任何格式的可读格式

select from_unixtime(UNIX_TIMESTAMP('2013-11-26 01:24:34'),"%Y-%m-%d");

select from_unixtime(UNIX_TIMESTAMP('2013-11-26 01:24:34'),"%Y-%m-%d");

For in detail you can visit link

有关详细信息,您可以访问链接

回答by Christian Nyembo

$date= new DateTime($row['your_date']) ;  
echo $date->format('Y-m-d');