Separate year / month

2

I have the following date format:

201705

I would like to put a / between the year and the month. How do I do this?

    
asked by anonymous 08.08.2017 / 23:18

1 answer

4

If you're working with dates, use DateTime::createFromFormat :

$date = DateTime::createFromFormat('Ym', '201705');
echo $date->format('Y/m');

See the example on ideone

If it's just a string with this default, you can use substr_replace :

echo substr_replace('201705','/', 4, 0);

See the example on ideone

    
08.08.2017 / 23:36