php 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
php_postgresql
Forum Newbie
Posts: 13
Joined: Sat Apr 19, 2008 9:37 am

php date format

Post by php_postgresql »

i have a date retrieved from database...... stored in $dateofpurchase........ i want to format it to be viewed like..... Jan. 1, 2007 .....i tried strtotime function and it gives me wrong result of conversion........

im using postgresql :D thanks
bhonan
Forum Newbie
Posts: 14
Joined: Sat Feb 02, 2008 12:55 pm

Re: php date format

Post by bhonan »

not sure how postgresql formats the date, but for mysql I had to take the date and use the explode() function to split the date in to 3 parts, month, year, and day. (YYYY-MM-DD to YYYY, MM, DD) Then you can use the 3 parts and shuffle them around and arrange it in the way you prefer. I did it in reverse to submit info into my database ($today = date("Y-m-d");)
User avatar
lafever
Forum Commoner
Posts: 99
Joined: Sat Apr 05, 2008 2:03 pm
Location: Taylor, MI

Re: php date format

Post by lafever »

Try this. Just change $date to the date from database.

Code: Select all

 
$date = '0000-00-00 00:00:00'; // date from database
$format_date = date('M j Y', strtotime($date));
 
Also, read the date function
php_postgresql
Forum Newbie
Posts: 13
Joined: Sat Apr 19, 2008 9:37 am

Re: php date format

Post by php_postgresql »

thanks lafever! :D
Post Reply