Date format

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Date format

Post by xionhack »

Hello. I'm pulling a date from a database through the php. When I pull it up it will say something like 2009-06-02. What I want it to do is to put it "February the 6th 2009". How can I do that? Thanks!
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Date format

Post by Benjamin »

You can do it in your database query: http://dev.mysql.com/doc/refman/5.1/en/ ... ate-format

Otherwise you can use strtotime() and date() to format the date.
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Re: Date format

Post by xionhack »

I've been looking but I havent found what is the right code for the format that I want. Can you help me? Thanks!
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Date format

Post by Benjamin »

It's right on the page I sent you for the mysql method. For the php method you can go to php.net and search for date. That will show you a chart of the different keys used for formatting the date.
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Re: Date format

Post by xionhack »

Lol! I'm sorry, but I honestly cannot see the format that I want there or in the php.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Date format

Post by Benjamin »

You'll have to use the keys to format the date yourself. For example, Y stands for the 4 digit year.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Date format

Post by susrisha »

Code: Select all

<?php
$timer_given = '2009-06-02';
$my_time = strtotime($timer_given);
$my_date = date('d:F:Y',$my_time);
echo $my_date; //gives  you the required time
//echo $my_time;
?>
 
Post Reply