-2

I receive some data, in it I get the date with this format:

250117 (means 25/01/2017)
50117 (means 05/01/2017

I didn't find any function that can convert this date using PHP.
Any suggestion will be great. Thanks

Qirel
  • 25,449
  • 7
  • 45
  • 62
dardar.moh
  • 5,987
  • 3
  • 24
  • 33
  • 4
    So you completely missed finding [DateTime::createFromformat()](http://www.php.net/manual/en/datetime.createfromformat.php) – Mark Baker Jan 25 '17 at 11:11
  • 3
    `$string = '50117'; $dto = DateTime::createFromFormat('dmy', sprintf('%06s', $string)); echo $dto->format('Y-m-d');` – Mark Baker Jan 25 '17 at 11:15

1 Answers1

2
<?php

$string = '50117';
$dto = DateTime::createFromFormat('dmy', sprintf('%06s', $string));
echo $dto->format('d/m/Y');

?>