PHP read date from filename and rewrite date format

I have a file called TAQB20170824DVF-RW314.pdf within the filename is the date “20170824“. Date strings change daily, file name lengths and names change daily.

I am already able to extract it and make it a variable.

Example:

$oldFileDate = "20170824";

How would I go about rewriting that date into 08-24 or 08-24-2017 even as a variable?

or

Replace that within the file name itself? Like TAQB08-24-2017DVF-RW314.pdf

Try

$time = strtotime('20170824');
$newformat = date('m-d-Y',$time);
echo $newformat;

It prints: 08-24-2017

I’m not quite sure how you extract it, but I think you have no problem with combine it again.

$newDate = substr($oldFileDate, 4, -2) . “-” . substr($oldFileDate, -2) . “-” . substr($oldFileDate, 0, 4);

Try this

$string = "TAQB20170824DVF-RW314.pdf";

    $rest = substr("$string", 4, 8);
    $first = substr("$string", 0, 4);
    $second = substr("$string", 12);
    $restf = substr($rest,0,4);
    $rests = substr($rest,4,2);
    $restt = substr($rest,6,2);
    echo $first . $rests ."-" . $restt . "-" . $restf . $second;

this is the output : TAQB08-24-2017DVF-RW314.pdf