format("yourFormatSpecifier"); Now you can implement the above syntax in PHP code to extract the unique date from the datetime field . The PHP code is as follows-$MySQLDataBaseDateTime="2018-02-1313:10:15""/> format("yourFormatSpecifier"); Now you can implement the above syntax in PHP code to extract the unique date from the datetime field . The PHP code is as follows-$MySQLDataBaseDateTime="2018-02-1313:10:15"">

Home  >  Article  >  Database  >  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?

WBOY
WBOYforward
2023-08-30 17:25:011195browse

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");

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");

This is the screenshot of the PHP code -

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

Output

13/02/2018

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete