473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Mysql Order By Date is having some issues...

Hi , I have a site..where i need to list records based on the modified date...im storing the date in the table like this "2 July, 2009, 8:37 am"....and the query i write is "SELECT * FROM Table ORDER By profile_updated_date DESC"

profile_updated_field will have values similar to 2 July, 2009, 8:37 am....and the listed records order is not correct...the data type for this fields is varchar...what could be the issue..i tried many way to solve this..please suggestion a solution..
Really appreciate your help...

Regards,
Unni
Jul 3 '09 #1
2 3068
Annalyzer
122 100+
Well, it seems to me that if you have a field that holds dates and times, then you might want to think about using a datetime type instead of a varchar. Varchar is going to sort in alphanumeric order exactly the way they are written which puts"1 Dec" before "1 Nov" before "1 Oct" and so on. Datetime will sort in the order you are expecting.
Jul 4 '09 #2
Atli
5,058 Expert 4TB
Hi.

I'd have to agree with Annalyzer.

Dates should always be stored using the date types: Date, Time, DateTime or Timestamp.
Unless you have a very very very good reason not to.

You should never store dates as strings (VarChar, Char, Text).
If you store them as strings (or integers, as some people seem to think is best) you will have to manually handle how they are sorted, compared, etc... because MySQL will simply look at them as strings (or numbers) and treat them accordingly.

So my advice to you is: convert your string date fields into real date types.
Then MySQL will sort them for you.
Jul 4 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: bruce | last post by:
Hi... Update.... We have the following setup in our httpd.conf file. We've tried to give what's related to the issue. We're trying to set up a virtual host for a test project. The behavior...
133
by: jonathan | last post by:
hey all, I realize that this question might pop up from time to time, but I haven't seen it a while and things might of changed, so - Right now (July 2004) how does mysql stand up in...
2
by: Lotfi | last post by:
Hi I am trying to access MySQL DB with C++ Builder 6 pro, I have Apache 2 under W2000 pro and MySQL 4 I found http://crlab.com/mydac/ but it is not free :-( but the trial version seems to...
2
by: m.k.ball | last post by:
Thanks Rich - that's great. Before I found this group, I thought I had a reasonable understanding of SQL (well, MySQL's implementation of it, at least) but the truth is there are great chunks that...
0
by: xkp | last post by:
i am having problems with this query which worked perfrcly on mysql 3.0. It is able to extract dowloaders from a table and group them by date. select count(*) AS downloaders,...
7
by: Martien van Wanrooij | last post by:
I have been faced a couple of times with the situation that I wanted to write a script and was worried about a too frequent opening and closing mysql connections. To give some examples: 1)I...
8
by: The Natural Philosopher | last post by:
This is so weird. What I am trying to do is to upload files and stuff them in a mysql database. Everything works except the file content is zero. using the load_file command from mysql...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.