Home > Backend Development > PHP Tutorial > Two ways to convert a string into a date in PHP and store it in the database_PHP Tutorial

Two ways to convert a string into a date in PHP and store it in the database_PHP Tutorial

WBOY
Release: 2016-07-13 10:31:35
Original
790 people have browsed it

The first way

Copy code The code is as follows:

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

The second way
Copy code The code is as follows:

$date = "2011-12-12";
$year=((int)substr($date,0,4));//Get the year
$month=((int)substr( $date,5,2));//Get the month
$day=((int)substr($date,8,2));//Get the day
$_date = date("M-d-Y" ,mktime(0,0,0,$month,$day,$year));

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/762209.htmlTechArticleThe first way to copy the code is as follows: $date= date("Y-m-d",strtotime("2011-12 -12")); The second way to copy the code is as follows: $date = "2011-12-12"; $year=((int)substr($date,0,...
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