![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements