In this post you will learn How to Convert a String into Date Format in PHP.
During development of a PHP calendar, I needed to convert a string to a PHP date, suppose the following string:
I wanted to convert this date into a format understandable by PHP: 2015-01-29.
The following code shows in two steps the use of the strtotime() and getDate() function to convert a string date into a PHP date structure:
// (1) returns a Unix timestamp, like 1422486000
$time = strtotime("2011/05/21");
// (2) getDate() returns an array that contains the
// information of this timestamp, or local time if no
// timestamp is not given
$date = getDate($time);
echo "<pre>"; //it's not important
The structure of the $ date variable will be displayed like this:
it works and even if it is not the best structure that can be obtained, it is possible at least to get the basic information on the day, the month, and the current year.