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
Date Formating
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Date Formating
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
Re: Date Formating
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 :
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')..."
?>