Current location: Hot Scripts Forums » Programming Languages » PHP » retrieving date from mysql.


retrieving date from mysql.

Reply
  #1 (permalink)  
Old 03-20-08, 12:44 PM
macintosh macintosh is offline
Newbie Coder
 
Join Date: Mar 2007
Posts: 84
Thanks: 1
Thanked 0 Times in 0 Posts
retrieving date from mysql.

Hey
I retrieve the date from mysql and it gives the output like
PHP Code:

2008-03-20 19:23:03 

, i want to display the date in the following format..

Code:
March 20, 2008 At 7:23 Pm
Is there any function to get that format of output?
At the moment i insert value in mysql with NOW() and the mysql column type is "datetime".
Reply With Quote
  #2 (permalink)  
Old 03-20-08, 01:33 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Use the strtotime() function to get the time as a unix format and then use the date() function to replace it with the correct output

Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #3 (permalink)  
Old 03-20-08, 01:36 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
You can convert it like this:

PHP Code:

$time="2008-03-20 19:23:03";
$tm strtotime($time);
echo 
date("F j, Y \\A\\t g:i A",$tm); 
It will give you this result:
Code:
March 20, 2008 At 7:23 PM
__________________
Jerry Broughton

Last edited by job0107; 03-20-08 at 01:54 PM.
Reply With Quote
  #4 (permalink)  
Old 03-20-08, 05:18 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Using the mysql DATE_FORMAT() function in your SELECT query will result in the quickest code. No slow php code (strtotime() and date()) is needed.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #5 (permalink)  
Old 03-20-08, 05:31 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Nice, hadn't seen that before. Thanks Mab. Will have to remember that one
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #6 (permalink)  
Old 03-20-08, 05:38 PM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
So Mab what is the full code?
__________________
Can you think outside the box but remain inside the box?
Reply With Quote
  #7 (permalink)  
Old 03-20-08, 05:50 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Take a look here
http://dev.mysql.com/doc/refman/5.0/...on_date-format
Show's how to use it in a query

Also here shows you how
http://www.plus2net.com/sql_tutorial/date_format.php
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
date format mysql and php Deansatch PHP 9 03-28-08 04:06 AM
MYSQL Error - Date select problem vivabensmith PHP 2 10-16-07 03:02 AM
converting date-string to Date object UnrealEd Everything Java 4 05-15-07 06:20 PM
MySQL to Text File, Plus Limit by Date Korrupt PHP 1 09-11-04 02:21 PM
inserting and retrieving date and time from mysql database stealth04 PHP 5 07-29-04 11:19 AM


All times are GMT -5. The time now is 07:38 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.