Solved

Formatting dates - PHP

Posted on 2011-09-10
4
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

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 110

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

617 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