Problem with sorting dates

I am taking date from the user in mm/dd/yyyy in the text field.

Since I am maintaing a document management system,

I need to sort docs with respect to dates. Latest date first.

Can anyone help me how do I do this.

I have to get docs from database(mysql) and I cant use order by ....

Please help

[331 byte] By [aniketh_parmara] at [2007-11-27 7:52:41]
# 1
Why can't you use order by. If they are stored in a date type they can b e in order by myDate descLena
LenaBa at 2007-7-12 19:33:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
The problem is that I want the user to enter in mm/dd/yyyy format from the form I have provided during registration and mysql is expecting in yyyy/mm/dd.Is there any way out to this
aniketh_parmara at 2007-7-12 19:33:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

How you enter and what gets stored and what gets displayed are controlled by your formating and can be 3 different things.

If you use an sqldate as a type for the mysql then you have raw date data ( some big integer type). This you push through a format to display.

Calendar work = Calendar.getInstance();

java.sql.Date sqldate = new java.sql.Date(work.getTimeInMillis());

String displayDate= sqldate.toString();

gives you todays date in the format yyyy-mm-dd

to use something else see:

http://java.sun.com/docs/books/tutorial/i18n/format/simpleDateFormat.html

In the mySQL dates are stored in a sortable format - how they show is NOT how they are stored.

I have dates in mySQL also, I have to display the records in ascending or descending order depending on the module.

Dates are a ***** to work with. You get it working on your local host and then you up load it to your server and it is running with a different date format and everything crashes.

Just wait till they ask for time, it is even worse.

so basically

1- input your date info

2 - tranfrom it into sql date format

3 store it inmysql as a date

4 search it and generate a datset in order of xdate desc

5 read through the data set and format your date for display

Lena

LenaBa at 2007-7-12 19:33:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Any one please reply to this post.

I want to take date from use in mm/dd/yyyy format in textbox.

I want to strore it in mysql DB as a date(data type). How do I convert it to date from string.

Next when I retrieve from DB. It should display in mm/dd/yyyy.

As we know that mysql accepts date in yyyy/dd/mm.

How to solve this prob

aniketh_parmara at 2007-7-12 19:33:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Hi Lena,

Sorry for the above message. I writing the above message when u sent me the reply.

The only prob I am facing is when I get date from database it is in yyyy-dd-mm format. How do I make it in mm-dd-yyyy.

Please Help me with this.

Thats the crucial part of my project

aniketh_parmara at 2007-7-12 19:33:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Hii Lena,I have got the solution.thx
aniketh_parmara at 2007-7-12 19:33:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
sorry for not replying but I think we are many hours apart and I posted quite late at night.I am glad you found out. Date handling is important and not easy.Lena
LenaBa at 2007-7-12 19:33:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...