1

I have the following numbers (actually I have to get these from a text file enclosed in " ").
How do I turn these into a date?
101887 (turns to October 18, 1987)
022500 (turns to February 25, 2000)

rekt
  • 65
  • 1
  • 11
  • 1
    `$dto = DateTime::createFromFormat('mdy', '101887');` Then you can format it however you want using the format() method, [e.g](https://3v4l.org/UKp4E) – Mark Baker Jan 23 '16 at 15:10

1 Answers1

3

You can accomplish this by parsing the string and then feeding it into strtotime and then date:

$str = '101887';
$str = $str[0].$str[1].'/'.$str[2].$str[3].'/'.$str[4].$str[5];
echo date('F jS, Y', strtotime($str));
wogsland
  • 9,106
  • 19
  • 57
  • 93