How to convert php sql string to date

藏色散人
Release: 2023-03-13 20:28:02
Original
1954 people have browsed it

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"));
Copy after login

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));
Copy after login

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!

Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!