By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

date_format problem

P: 93
I am trying to take a date in the format "YYYY-MM-DD" and get from it the month as a word (e.g. July) and the day as a 2 digit number (e.g. 24).

I am trying to use the date_format function, (new as of php 5.2) but I can't get it to work...

$date = "2007-06-22 00:00:00";
//I also tried $date = "2007-06-22"; but that didn't work either
//I also tried adding strtotime($date); but that didn't help!

$month = date_format($date , 'F');
$day = date_format($date, 'd');

Feb 17 '07 #1
Share this Question
Share on Google+
3 Replies

P: 93
I am running PHP 5.2.1 on mac OS 10.4.8
Feb 17 '07 #2

Expert 2.5K+
P: 4,258
Try this one
[php]echo date('l, F jS Y', strtotime($date ));[/php]

Ronald :cool:
Feb 18 '07 #3

Expert 5K+
P: 5,058

I modified you code so it returns to you the month as 3 letter word and the day as 2 digits, like this:
Sep 05

$date = "2007-06-22 00:00:00";

// get the parts you need from the string
// and turn them into numbers (abs)
$year = abs(substr($date, 0, 4));
$month = abs(substr($date, 5, 2));
$day = abs(substr($date, 8, 2));

// Create the output string
$output = date("M d", mktime(0, 0, 0,$month, $day, $year));

// print
print $output;

You should check out the date and mktime methods at

Hope this helps.
Feb 18 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.