954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

best way to structure time?

Hi all, just wondering what the best way is to structure time in sql database. For example, at present i use this format ; 19/08/2011 (which is day/month/year). when i call this in a sql statement, it shows all results, but not in a chronological order. Can any body solve this?

Cheers lovely people

gotboots
Junior Poster in Training
54 posts since Jun 2011
Reputation Points: 12
Solved Threads: 4
 

You need to sort the result set using Order by on the date column in your SQL.

ex

select * From employee order by date_of_join
debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

I have a sort on my statement already though bud, but it sorts on the first numbers first. I need it to sort in a chronological order. at present it sorts days regardless of the month eg:

21/08/2011
21/07/2011
20/08/2011
19/08/2011
18/08/2011
18/07/2011
17/07/2011

gotboots
Junior Poster in Training
54 posts since Jun 2011
Reputation Points: 12
Solved Threads: 4
 

that means you have not stored your date using "date" datatype, you might be using varchar datatype.

So in short change datatype to "date" of that column

urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: