Solved

Formatting dates - PHP

Posted on 2011-09-10
4
247 Views
Last Modified: 2012-05-12
How to I reformat the php date returned to this format?

Jan 23, 2011

This is the code I have:

echo $rows['date_m']; // Each of these fields are DATE type and print out entire date
echo ' ';
echo $rows['date_d'];
echo ' ';
echo $rows['date_y'];
0
Comment
Question by:msvarts
  • 2
4 Comments
 
LVL 10

Expert Comment

by:Derokorian
ID: 36517279
What is the output of those echo's? What exactly are you seeing? Without knowing what the input looks like its hard to tell you how to get what you want. However, you can have a look at these functions:

http://www.php.net/strtotime
http://www.php.net/date
http://www.php.net/date_format
0
 

Author Comment

by:msvarts
ID: 36517321
Let me rephrase:

This is the code: echo $rows['date_m'];

and this is the output: 2011-10-10

I Just want it to read: Oct
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 36517535
This is what is called an ISO-8601 date string.  That is how you keep dates for internal use in programs and data bases.  Learn all you need to know about formatting dates here.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 36517543
Looking at this page: http://us3.php.net/manual/en/function.date.php

It looks like you can make the transformation this way (assuming that $rows['date_m'] == '2011-10-10'):

$x = date('M', strtotime($rows['date_m'])); // CREATES 'Oct'

Or maybe this way:

$x = date('M j, Y', strtotime($rows['date_m'])); // CREATES 'Oct 10, 2011'
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question