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.
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!