
- 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
Extracting only date from datetime field in MySQL and assigning it to PHP variable?
You need to use DateTime class if you want to extract the only date from datetime field. The syntax is as follows −
DateTime::createFromFormat("Y-m-d H:i:s",yourDateTimeValue)->format("yourFormatSpecifier");
Now you can implement the above syntax in your PHP code to extract the only date from datetime field. The PHP code is as follows −
$MySQLDataBaseDateTime = "2018-02-13 13:10:15"; echo DateTime::createFromFormat("Y-m-d H:i:s",$MySQLDataBaseDateTime)->format("d/m/Y");
Here is the screenshot of the PHP code −
Output
13/02/2018
- Related Articles
- Get only the date from datetime in MySQL?
- How to select only MySQL date from datetime column?
- Compare DATE string with string from MySQL DATETIME field?
- Add DATE and TIME fields to get DATETIME field in MySQL?
- MySQL query to get current datetime and only current date
- How to extract from datetime column in MySQL by comparing only date and ignoring whitespace?
- How to update date of datetime field with MySQL?
- Create DATETIME from DATE and TIME in MySQL?
- How to part DATE and TIME from DATETIME in MySQL?
- MySQL Query to convert from datetime to date?
- Compare only day and month with date field in MySQL?
- How to get only Date portion from DateTime object in C#?
- How to compare DateTime Column with only Date not time in MySQL?
- MySQL query to get only the minutes from datetime?
- How to return today's records using DATE from DATETIME Field?

Advertisements