Solved

Formatting dates - PHP

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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 count occurrences of each item in an array.

708 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

12 Experts available now in Live!

Get 1:1 Help Now