I realized that when using plain text datatype fields it can't sort the date. However, when I set it to the DateTime field, my date has to be formatted like this:
0000-00-00 00:00:00
That's fine with me. I just need it to work since Im making a forum and it needs to be sorted by new posts. So I figured to get it to that format I made this code:
$date=date('Y-m-d G:i:s');
But it will not go in the database? Can someone show me how to correctly make the date and time, put it in the database but allow it to be sorted later?
Thanks.
Ugh! Just want to sort date
Moderator: General Moderators
Store it as a normal date time field and use mysql date functions to format it 
http://dev.mysql.com/doc/refman/5.0/en/ ... tions.html
http://dev.mysql.com/doc/refman/5.0/en/ ... tions.html
or just use a unix timestamp to sort, and use date() to print the date in a readable format
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
ill toss down my 2 cents and agree with scottayy. if you store it in unix timestamp it is very easy to order it in a SQL statement and you can always change the layout of the date using the date() function. Different places in the world show the time and the date in different formats and you should be able to show it to them accordingly.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: Ugh! Just want to sort date
Why not sort by post ID instead of date/time? Post ID should be as accurate of a sort field as a date/time field and a lot easier to query/sort by.xterra wrote:That's fine with me. I just need it to work since Im making a forum and it needs to be sorted by new posts.
As for the time issue, I tend to go with what all the other posters are saying. Use the MySQL UNIX_TIMESTAMP() function or use the strtotime() PHP function along with the date() function.
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA