php date... how do I rearrange this date/time from mysql row

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
syntax24
Forum Newbie
Posts: 11
Joined: Tue Jun 03, 2008 3:25 pm

php date... how do I rearrange this date/time from mysql row

Post by syntax24 »

I need to know how to format this time listed below into a webpage using php. It's the time used in the mysql table row... and I want to format it in a more userfriendly way. Can PHP pull that out of lastLogin and recognize it as a date/time?

2008-06-03 15:07:24
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: php date... how do I rearrange this date/time from mysql row

Post by RobertGonzalez »

PHP can do it, but it would be faster/more efficient to modify using the MySQL date functions during the select.
syntax24
Forum Newbie
Posts: 11
Joined: Tue Jun 03, 2008 3:25 pm

Re: php date... how do I rearrange this date/time from mysql row

Post by syntax24 »

umm... alright so if the row is a "datetime" format.... how do I modify it using sql query while pulling the data from a table...

(I am somewhat new to the whole sql query to modify date thing)...

if you could give me just a little bit more help, I'd appreciate it alot!

:D

Thanks!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: php date... how do I rearrange this date/time from mysql row

Post by RobertGonzalez »

Depending on how you want your date to look (have a look through the MySQL docs on Date and Time functions), you would do something like (in MySQL only):
[sql]SELECT DATE_FORMAT(`datefield`, '%M %e %Y') AS new_date_formatted FROM `tablename` WHERE `searchcolumn` = 'somevaluetoget';[/sql]
Post Reply