phpstringdatedate-formatting

Reformat date from Ymd to d-m-Y


I have a program that gererates data and with that data it includes the date in the format

20111212

(That would be today's date [12-12-2011]). Is there a way to explode that into the three segments like

2011
12
12

so I can put a - between those numbers?

My end aim is to have the date in the form DD-MM-YYYY.


Solution

  • If your format alway YYYYMMDD then first take 4 digits as year, then take 2 digits as month and last take 2 digits as date. see substring function for php in google.