0

database date format that i retrieve is

 $event_date='2013-01-20';

and i want to convert this format to like this Jan 1,2013

I have tried this

echo date('M d, Y',$event_date)
//but it is printing wrong value "Jan 01, 1970"

and giving error also: Notice (8): A non well formed numeric value encountered

if anyone can catch please help me to get correct value

Fabio
  • 23,183
  • 12
  • 55
  • 64
  • @MarkBaker sir your comment may be according to title not according to question.... i have described well my question and my try... it's your choice you want to close it or not..you have rights you can do it to improve your power!!!!!!!!!!!! – Kuldeep Choudhary Mar 04 '14 at 10:28
  • and which part of the accepted answer to the question I linked doesn't answer your own question? – Mark Baker Mar 04 '14 at 10:29
  • @MarkBaker may be anser same but not question...i already did know my answer but i was just missing a method strtotime ... – Kuldeep Choudhary Mar 04 '14 at 10:32

7 Answers7

2

You will need to use strtotime() function to correctly format the date since date() function expects second parameter to be a timestamp

echo date('M d, Y',strtotime($event_date));

From documentation

The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now, or the current time if now is not supplied.

Live working sample here

Fabio
  • 23,183
  • 12
  • 55
  • 64
2

date expects second parameter to be a timestamp http://php.net/date

http://php.net/strtotime is the way to go.

date('M d, Y', strtotime($event_date))

2cent
  • 211
  • 1
  • 5
1

You should do:

echo date('M d, Y',strtotime($event_date));
Ramesh
  • 4,223
  • 2
  • 16
  • 24
1

try this....

echo date('M d, Y',strtotime($event_date));
user1844933
  • 3,296
  • 2
  • 25
  • 42
1

Do like below

<?php  $event_date='2013-01-20';
echo date('M d, Y',  strtotime($event_date));
?>
Pratik
  • 810
  • 6
  • 26
1

Use DateTime to convert the Dateformat

   <?php
    $event_date='2013-01-20';
    $date = new DateTime($event_date);
    echo $date->format('M d, Y');
Nambi
  • 11,944
  • 3
  • 37
  • 49
1

try this :

$event_date='2013-01-20';

echo date('M d, Y',strtotime($event_date));
uvais
  • 416
  • 2
  • 6