Get only the date in timestamp in mysql
MysqlDateMysql Problem Overview
On my database under the t_stamp columns I have the date for example
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!
Mysql Solutions
Solution 1 - Mysql
You can use date(t_stamp)
to get only the date part from a timestamp.
You can check the date() function in the docs
> 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'
Solution 2 - Mysql
You can convert that time in Unix timestamp by using
select 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");
For in detail you can visit link
Solution 3 - Mysql
To get only date from timestamp in MySQL just use DATE_FORMAT(datetime, '%Y-%m-%d')
:
SELECT DATE_FORMAT('2013-11-26 01:24:34', '%Y-%m-%d');
> 2013-11-26
Solution 4 - Mysql
$date= new DateTime($row['your_date']) ;
echo $date->format('Y-m-d');