By 03/02/2016 7 Comments

Convert one date format into another in PHP

  • Use strtotime() to convert a date string into a timestamp. However, even strtotime() doesn’t recognize the y-m-d-h-i-s format.

PHP 5.3 and greater:

  • Use DateTime::createFromFormat. It allows you to specify an exact mask – using the date() syntax – to parse incoming string dates with.

PHP 5.2 and lower:

  • You will have to parse the elements (year, month, day, hour, minute, second) manually using substr() and hand the results to mktime() that will build you a timestamp.

Example:

$old_date = date('l, F d y h:i:s');              // returns Saturday, January 30 10 02:06:34
$old_date_timestamp = strtotime($old_date);
$new_date = date('Y-m-d H:i:s', $old_date_timestamp);   






Posted in: PHP, Solutions

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .