Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6729519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:17:59+00:00 2026-05-26T10:17:59+00:00

I am trying to order a database by date but I am having trouble

  • 0

I am trying to order a database by date but I am having trouble sorting it. The database is created in SQL through PHP and the column I want to use to sort by adds the date data in this format:

2011-10-26 07:10

The above date is also a ‘varchar’.
EDIT: changed to ‘datetime’ thanks to suggestions

Any idea so that I can sort the rows in the table using the date column?

I made a separate script to narrow this problem down:

<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("thoughtsdata",$con);


$order = "SELECT * 
FROM  `thoughts` 
ORDER BY  `thoughts`.`DateTime` ASC 
LIMIT 0 , 30";

if(!mysql_query($order,$con))
{
die('Could not order database: ' . mysql_error());
}


mysql_close($con);
?>

I now get no errors when running this script in my browser but my table remains unsorted:

  Edit    Inline Edit     Copy   Delete Hey sdfasdf    2011-10-26 19:41:00
  Edit    Inline Edit     Copy   Delete Hey asdfasdf    2011-10-26 07:47:00 
  Edit    Inline Edit     Copy   Delete Hey dfasdfasdf    2011-10-26 19:47:00   
  Edit    Inline Edit     Copy   Delete aaa how to sort this    2011-10-26 07:54:00 
  Edit    Inline Edit     Copy   Delete aaa any progress!!??    2011-10-26 08:13:00 
  Edit    Inline Edit     Copy   Delete oh no!  grrr    2011-10-26 08:21:00 
  Edit    Inline Edit     Copy   Delete zzTOp   thinking about sorting this out!    2011-10-27 19:12:00

What seems to me happening, is that the database is sorted but it does not stay like that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:18:00+00:00Added an answer on May 26, 2026 at 10:18 am

    You could try using an order clause like this:

    ORDER BY UNIX_TIMESTAMP(fieldname) ASC
    

    However, if your field is in YYYY-MM-DD hh:mm format like it looks, an alpha sort should work correctly. This is all under the assumption that you are working with an existing system and can’t / aren’t allowed to change the field’s datatype.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find the best way to design the database in order
I'm trying to use the DataAnnotationsModelBinder in order to use data annotations for server-side
I'm trying to grab the date from my database in a standard timestamp and
I am trying to get the week of a date from the database and
I'm trying to learn to use PDO instead of MySQLi for database access and
I have several different tables in my database and I'm trying to use Sphinx
I'm have a database customer name and date are the composite keys. I'm trying
I'm trying order a Linq to NHibernate query by the sum of it's children.
I'm trying to order items based on an attribute value: <xsl:apply-templates select=Question> <xsl:sort order=ascending
I'm trying to order the results of the get_list_or_404 method get_list_or_404(...).order_by('name') doesn't seem to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.