PHP How to reverse engineer the day of the year 3212 (YDDD) into 2013-08-01 (YYYY-mm-dd)

date, php

Solution

$date = "3212";
echo DateTime::createFromFormat("Yz", "201$date")->format("Y-m-d");
// 2013-08-01

- `DateTime::createFromFormat()`

- See it running online

Problem

I have a date in `YDDD` format such 3212 I want to convert this date into default date string i.e. 2013-08-01 in PHP Since the first value `Y` is the only character for Year, so I've decided to take the first three characters from the current Year i.e. 201 from 2013 The following is the code I've written for year ``` <?php $date = "3212" $y = substr($date,0,1); // will take out 3 out of year 3212 $ddd = substr($date,1,3); // will take out 212 out of year 3212 $year = substr(date("Y"),0,3) . $y; //well create year "2013" ?> ``` Now How can I use `$year` and `212` to convert it into 2013-08-01 using PHP EDIT FYI: My PHP Version is `5.3.6`

Original source