Well, the best I could find was just to use sprintf ... mktime needs to set the locale for the time, and I also don't like going through the timestamp to format the date.
So just print the formatted fields:
// Parse from YYYY-MM-DD to associative array $date = date_parse_from_format("Ymd", "2014-07-15"); // Write back to DD/MM/YYYY with leading zeros echo sprintf("%02d/%02d/%04d", $date["day"], $date["month"], $date["year"]);
EDIT: but this solution requires some tweaking if you need, for example, to print only the last 2 digits of the year (for example, from 1984 to "84").
source share