Date Formating

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
shahzad429
Forum Newbie
Posts: 8
Joined: Mon Mar 03, 2008 12:39 pm

Date Formating

Post by shahzad429 »

I am storing date as 2010-01-26 in Mysql

But i want to display it as November 29th, 2009 to the user

how to format the date??

thanks in advance
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Date Formating

Post by requinix »

Format a date in MySQL?
Format a date in MySQL?
http://www.google.com/search?q=format+date+mysql
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Date Formating

Post by social_experiment »

Store the date as an integer inside the database ( as received when you use the time() function ) then you can manipulate it in whichever way you want using the date() function. The code that will give you the format you are looking for ( php format not mySQL format ) is :

Code: Select all

<?php 
 date('F jS, Y', $valueRetrievedFromDb);
?> 
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Date Formating

Post by requinix »

For that matter,

Store the date as a DATE inside the database ( as received when you use the date() function ) then you can manipulate it in whichever way you want using the DATE_FORMAT() function. The code that will give you the format you are looking for ( MySQL format not PHP format ) is :

Code: Select all

<?php 
"SELECT DATE_FORMAT(fieldFromTable, '%M %D, %Y')..."
?> 
Post Reply