Solved

Formatting dates - PHP

Posted on 2011-09-10
4
244 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 108

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now