?
Solved

string input of a date I want to change and output

Posted on 2003-02-19
6
Medium Priority
?
283 Views
Last Modified: 2008-03-06
i am grabbing the date a table in my DB was last changed.  I've got the date but it is in the format:
2003-02-20 05:14:10
I want to change it to
Month day, year

but if I do something (or anything) like this:

$updated = date("F d, Y", "2003-02-20 05:14:10");

It will only take the "2003" and drop the rest.  

Any suggestions???

0
Comment
Question by:joshence
6 Comments
 
LVL 1

Expert Comment

by:cneelus
ID: 7985660
You can use this
$updated = date("F d, Y", mktime(5,14,10,02,20,2003));
0
 
LVL 2

Expert Comment

by:laurly
ID: 7985917
if you are using mysql there is a function called date_format for formating dates

manual entry:
http://www.mysql.com/doc/en/Date_and_time_functions.html

example:
SELECT DATE_FORMAT('2003-02-20 05:14:10','%m-%D-%Y');


laurly
0
 
LVL 6

Expert Comment

by:carchitect
ID: 7986090
yeah laurly is right and i am late....
date_format will sole your purpose....

SELECT DATE_FORMAT(2003-02-20 05:14:10','%m %e,%Y');

regards


0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:joshence
ID: 7987854
I like what laurly has to say, and I think I can get it to work...but as of now it is a no go.  Here is my SQL Query:

show table status from *database* like '*tablename*';

and that returns an array with a "column name" called Update_time along with many others (not all dates).

So my new question is.  How can I get mySql to pull ONLY that column and then arrange the date the way I want.  


Joshua
0
 
LVL 1

Accepted Solution

by:
s-maxim earned 400 total points
ID: 7988159
Then, your could also use the PHP native function strtotime() for recognizing the date's format:

$new_date = date("F d, Y", strtotime($date_returned_from_db));

Maxim Maletsky
maxim@php.net
0
 

Author Comment

by:joshence
ID: 7988399
s-maxim,
Thanks...that was the function I was looking for.  Very nice.  
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…
Suggested Courses

571 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