
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Get only the date in timestamp in MySQL?
In order to get the date from the timestamp, you can use DATE() function from MySQL.
The syntax is as follows −
Syntax
SELECT DATE(yourTimestampColumnName) as anyVariableName from yourTableName;
To understand the above syntax, let us first create a table. The query to create a table is as follows −
mysql> create table DateFromTimestamp -> ( -> ShippingDateTime timestamp -> ); Query OK, 0 rows affected (0.60 sec)
Insert date and time for the column ShippingDateTime we created above.
The query to insert record is as follows −
mysql> insert into DateFromTimestamp values('2012-12-26 13:24:35'); Query OK, 1 row affected (0.14 sec) mysql> insert into DateFromTimestamp values('2013-11-26 14:36:40'); Query OK, 1 row affected (0.13 sec) mysql> insert into DateFromTimestamp values('2016-07-22 15:20:10'); Query OK, 1 row affected (0.19 sec) mysql> insert into DateFromTimestamp values('2017-11-04 04:25:30'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select command. The query is as follows −
mysql> select *from DateFromTimestamp;
Output
+---------------------+ | ShippingDateTime | +---------------------+ | 2012-12-26 13:24:35 | | 2013-11-26 14:36:40 | | 2016-07-22 15:20:10 | | 2017-11-04 04:25:30 | +---------------------+ 4 rows in set (0.00 sec)
The following is the query to display only date from a timestamp using date() function −
mysql> select date(ShippingDateTime) as OnlyDatePartFromTimestamp from DateFromTimestamp;
Output
+---------------------------+ | OnlyDatePartFromTimestamp | +---------------------------+ | 2012-12-26 | | 2013-11-26 | | 2016-07-22 | | 2017-11-04 | +---------------------------+ 4 rows in set (0.00 sec)
- Related Articles
- Display only date from timestamp value in MySQL
- Convert DATE timestamp to return only the month name in MySQL
- Get timestamp date range with MySQL Select?
- Get only the date from datetime in MySQL?
- Display Timestamp before the current date in MySQL
- Select timestamp as date string in MySQL?
- How to select date from timestamp in MySQL?
- Get first date from timestamp in MySQL group by another column with duplicate value
- Set current date and time to timestamp in MySQL
- MySQL query to select date from timestamp?
- Combine date and time column into a timestamp in MySQL?
- How to search for a date in MySQL timestamp field?
- MySQL query to get current datetime and only current date
- Convert MySQL Unix-Timestamp format to date format?
- How to get day name from timestamp in MySQL?

Advertisements