omg omg - 1 year ago 62
PHP Question

Manipulating Dates in PHP without using Regular Expressions

Is there a way to change a date from

1985-12-15


to

1985-12


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.