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?
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?
m
is number of month. Use d
in reverse order:
$evnt_start_date = date('d F', strtotime($evnt_details['events_date']));
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)
?>
Below code will give you 24 June
.
date("d F",strtotime($evnt_details['events_date']));
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
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