Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get only the date in timestamp in mysql

Tags:

date

mysql

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!

like image 294
sleepsleepsleep90731 Avatar asked Nov 26 '13 21:11

sleepsleepsleep90731


People also ask

How do I get just the date from a timestamp?

In order to get the date from the timestamp, you can use DATE() function from MySQL.

How do I separate a date from a timestamp in SQL?

SELECT blah FROM tbl WHERE DATE(some_datetime_field) = '2012-04-02'; That will select any rows such that the date part of some_datetime_field is 4 Apr 2012.

How do I select a specific date in MySQL?

You can use DATE() from MySQL to select records with a particular date. The syntax is as follows. SELECT *from yourTableName WHERE DATE(yourDateColumnName)='anyDate'; To understand the above syntax, let us first create a table.


2 Answers

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'

like image 186
Filipe Silva Avatar answered Sep 20 '22 17:09

Filipe Silva


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

like image 31
Dilraj Singh Avatar answered Sep 19 '22 17:09

Dilraj Singh