I have $date_string = '12/1/2014';
I need:
- To parse it into a timestamp number (to save in a DB)
- And then parse that timestamp to output in a different format, e.g.
December 1, 2014
I am assuming that using the DateTime class would be the preferred method (and I personally find it very convenient).
// timestamp
$date_string = '12/1/2014'; // input
$d1 = new DateTime($date_string);
$date_timestamp = $d1->getTimestamp(); // output
// re-format
$date_timestamp = '1417410000'; // input
$d2 = new DateTime("@$date_timestamp"); // append @ to hint the timestamp
$date_formatted = $d2->format('F j, Y'); // output
However, I am curious what would be the fastest way to perform both parse operations.