-5

I want to change format of date by 2013-08-09 to 09-Aug-2013, I tried this:

echo $date=date("Y-m-d");
//output 2013-08-09
echo date("d-M-Y",mktime(0-0-0,$date));

but this code showing 10-Aug-2013 I dont know why this showing date 10 instead of 09.

Answer would be highly appreciated , thanks in advance

Dinesh
  • 447
  • 1
  • 6
  • 22
  • 1
    Why do not simply look into manual: http://php.net/manual/en/function.date.php ?? – Alma Do Aug 09 '13 at 13:41
  • 2
    your `mktime()` call is completely and utterly wrong. I suspect you intended to use `strtottime()` instead, but the way you're doing it would be badly wrong even for that. I suggest reading some basic examples from the manual. – Spudley Aug 09 '13 at 13:45

2 Answers2

6

following is easier:

echo date("d-M-Y",strtotime($date));

at mktime you have to subtract one day

1

You aren't passing in the parameters to mktime properly. mktime requires 6 integer parameters where as you have 1 integer and 1 string here.

Try using a DateTime object instead:

$date = new DateTime();
echo $date->format('d-M-Y');
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156