Solved

Formatting dates - PHP

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Installer 5 39
php help 34 58
IP 10.0.1.2 / 255.0.0.0 61 57
How to eliminate "realname" and "email" from formMail.php (tectite.com) results. 3 36
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 …
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…
The viewer will learn how to count occurrences of each item in an array.
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…

821 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