-2

How do I convert a Unix timestamp to the following custom date format: '28-Jan-2017'? Below is my attempt.

$unixT = 1532728800;

$date = new DateTime();
$date -> setTimestamp($unixT);
echo $date->format('d-m-Y');

With above I get '28-07-2017'.

tim
  • 163
  • 1
  • 2
  • 11
  • 1
    try to use `d-M-Y` note capital `M` – Iłya Bursov Aug 08 '17 at 16:18
  • Possible duplicate of [Convert one date format into another in PHP](https://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – Qirel Aug 08 '17 at 16:18
  • @LLya Bursov, thanks for your help man. If you put it down as an answer I can set it as the solution – tim Aug 08 '17 at 16:20
  • 1
    `DateTime::format()` uses the same formats as `date()` - so have a look at the manual: http://php.net/manual/en/function.date.php – Qirel Aug 08 '17 at 16:21

1 Answers1

2

Please use capital (M) instead of small (m).

echo $date->format('d-M-Y');

Demo

Kamran Jabbar
  • 858
  • 7
  • 21