0

I have a date: 2015-06-24

I want to display it as 24 June

I have written this code.

$evnt_start_date = date('F m', strtotime($evnt_details['events_date']));

It displays the result like: June 06

What am I doing wrong?

Saswat
  • 12,320
  • 16
  • 77
  • 156

5 Answers5

5

m is number of month. Use d in reverse order:

$evnt_start_date = date('d F', strtotime($evnt_details['events_date']));
Marcos Pérez Gude
  • 21,869
  • 4
  • 38
  • 69
1

read more about date()

<?php
    echo date('d F', strtotime($evnt_details['events_date']));
?>

This will output in this format DD-MM

date() Formatting Methods...

<?php
// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone

$today = date("F j, Y, g:i a");                 // March 10, 2001, 5:16 pm
$today = date("m.d.y");                         // 03.10.01
$today = date("j, n, Y");                       // 10, 3, 2001
$today = date("Ymd");                           // 20010310
$today = date('h-i-s, j-m-y, it is w Day');     // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // it is the 10th day.
$today = date("D M j G:i:s T Y");               // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h');     // 17:03:18 m is month
$today = date("H:i:s");                         // 17:16:18
$today = date("Y-m-d H:i:s");                   // 2001-03-10 17:16:18 (the MySQL DATETIME format)
?>
Manjeet Barnala
  • 2,975
  • 1
  • 10
  • 20
0

Below code will give you 24 June.

date("d F",strtotime($evnt_details['events_date']));
JiteshNK
  • 428
  • 2
  • 11
0

Many of the answers above will work just fine for you, but I'd like to suggest a really awesome way to work with Dates and Time in PHP. It's DateTime and their related classes; to answer your question:

$dateString = '2015-06-24';
$date = new \DateTime($dateString);
$evnt_start_date = $date->format('d F');

See the following links:

http://php.net/manual/en/class.datetime.php - DateTime

Some extra reading that will help both now and in the future:
http://www.phptherightway.com/#date_and_time - PHP the right way

Emmanuel Okeke
  • 1,452
  • 15
  • 18
-1

Use j for not leading 0 and use d for leading zero.

Not leading Zero:

$evnt_details['events_date'] = '2015-06-24';
echo $evnt_start_date = date('j F', strtotime($evnt_details['events_date']));//24 June

Leading Zero:

$evnt_details['events_date'] = '2015-06-24';
echo $evnt_start_date = date('d F', strtotime($evnt_details['events_date']));//24 June
Murad Hasan
  • 9,565
  • 2
  • 21
  • 42