Home  >  Article  >  Backend Development  >  How to convert php sql string to date

How to convert php sql string to date

藏色散人
藏色散人Original
2021-11-16 09:12:121982browse

php Method to convert sql string to date: 1. Convert through "date("Y-m-d",strtotime(""));"; 2. Convert through "date("M-d-Y",mktime(0, 0,0,$month,$day,$year));" method conversion.

How to convert php sql string to date

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to convert php sql string to date?

Two ways for php to convert strings into dates and store them in the database

The first way

The code is as follows:

$date= date("Y-m-d",strtotime("2011-12-12"));

The second way

The code is as follows:

$date = "2011-12-12";
$year=((int)substr($date,0,4));//取得年份
$month=((int)substr($date,5,2));//取得月份
$day=((int)substr($date,8,2));//取得几号
$_date = date("M-d-Y",mktime(0,0,0,$month,$day,$year));

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert php sql string to date. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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