1.1.1 string conversion to datetime object
Use Date_create_from_format function:
Date_create_from_format (' y-m-d h:i:s ', ' 2015-08-12 09:50:23 ')
1.1.2 date Time object converted to string
A DateTime object has a member function format :
$dt = Date_create_from_format (' y-m-d h:i:s ', ' 2015-08-12 09:50:23 ');
$DTSTR = $dt->format (' y-m-d h:i:s ');
1.1.3 calculates relative dates based on a specified date
For example, a date is known to calculate that date one year ago / date, you can use date_interval_create_from_date _string Get the date time interval object, and then use date_add function gets the converted date:
$dt = Date_create_from_format (' y-m-d h:i:s ', ' 2015-08-12 09:50:23 ');
$interval = date_interval_create_from_date_string (' -365 days ');
$endTime = Date_add ($dt, $interval);
The above code is calculated a date a year before the specified date (not accurate, not considered leap years).
PHP-Date and time conversion