Get readable date from time() sent to database

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

liam_d

The original NP Emo KidEstablished Member
Impact
25
Hi everyone, just wondering how i can convert a time() that has been sent to a database to a readable date?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
In mysql you have the date_format function for that purpose
 
0
•••
The PHP date function is designed for this.
 
0
•••
what is your front end??
use date functions in vb or use visual data manager to do the same
 
0
•••
Well you can't sort a mysql query using a date, but you can but a timestamp i was told.

In my forum i update the topics "lastdate" field to a new timestamp when someone replies, and then the forum is sorted by timestamp to show newest topics with replies at the time, the way all forums work.
 
0
•••
date("d-m-Y", $row['time']);

where $row['time'] is the value from the database, hope that helps a bit
 
0
•••
Hmmm I think you can indeed sort on a datetime field, but instead display a properly formatted date using date_format for example
 
0
•••
Albino said:
date("d-m-Y", $row['time']);

where $row['time'] is the value from the database, hope that helps a bit

That is what i was looking for.

And someone told me exactly why not to use a "date(d-m-y)" thing for sorting stuff, and it was a good idea, so i use timestamps.

edit -> works perfectly as seen on my homepage http://www.altercoder.com/ in the "Latest Forum Posts" block :).

Thanks a lot! :D
 
Last edited:
0
•••
Something like this:
PHP:
select date_format(lastdate,'%d-%b-%Y %H:%i') as post_date
from [table]
order by lastdate desc

For performance reasons it would be best to do the sorting from SQL, not in PHP code.
 
0
•••
liam u asked the question right?
then y urself answering it
 
0
•••
yuvanextgen said:
liam u asked the question right?
then y urself answering it

Someone else answered it, if you are even reading this thread properly bud!
And if in future someone answeres there own question, it may be useful someone else if they are doing something the same or similair :)

sdsinc said:
Something like this:
PHP:
select date_format(lastdate,'%d-%b-%Y %H:%i') as post_date
from [table]
order by lastdate desc

For performance reasons it would be best to do the sorting from SQL, not in PHP code.

Of course i sort in the sql, but i am using this on the homepage just to show a simple date when the last post was added :) (www.altercoder.com).

My actual sql for sorting the topics in the forum is this:
PHP:
mysql_query("SELECT * FROM `forum_topics` WHERE `forumroot` = '" . $_GET['f'] . "' AND `sticky` = '1' ORDER BY `lastdate` DESC");

Thanks again people :)
 
Last edited:
0
•••
Appraise.net

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover
URLs.com
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back