Home > Database > Mysql Tutorial > Extract only date from datetime field in MySQL and assign it to PHP variable?

Extract only date from datetime field in MySQL and assign it to PHP variable?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-08-30 17:25:01
forward
1312 people have browsed it

If you want to extract a unique date from a datetime field, you need to use the DateTime class. The syntax is as follows -

DateTime::createFromFormat("Y-m-d H:i:s",yourDateTimeValue)->format("yourFormatSpecifier");
Copy after login

Now you can implement the above syntax in your PHP code to extract unique dates from datetime fields. 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");
Copy after login

This is the screenshot of the PHP code -

仅从 MySQL 中的日期时间字段中提取日期并将其分配给 PHP 变量?

Output

13/02/2018
Copy after login

The above is the detailed content of Extract only date from datetime field in MySQL and assign it to PHP variable?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template