omg omg - 1 year ago 69
PHP Question

Manipulating Dates in PHP without using Regular Expressions

Is there a way to change a date from




without using a regular Expression?

Answer Source
<?php echo date('Y-m', strtotime('1985-12-15')); ?>

That should do it.

This will, using strtotime, convert 1985-12-15 to a unix timestamp. The date function then takes a second parameter timestamp on which to format the date.