Get only the date in timestamp in mysql

MysqlDate

Mysql 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');

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionsleepsleepsleep90731View Question on Stackoverflow
Solution 1 - MysqlFilipe SilvaView Answer on Stackoverflow
Solution 2 - MysqlDilraj SinghView Answer on Stackoverflow
Solution 3 - MysqlTridev SharmaView Answer on Stackoverflow
Solution 4 - MysqlChristian NyemboView Answer on Stackoverflow